From 8a48f074d8c7c3c3b2b5b51e23e4d85132dec77b Mon Sep 17 00:00:00 2001 From: stippi Date: Fri, 21 May 2010 20:45:23 +0000 Subject: [PATCH] Handle B_RETURN and B_ESCAPE when the Find text control has focus. Refactored the code to visibly invoke a BButton and use it to show the respective buttons go down in the Find group. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@513 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowserWindow.cpp | 40 ++++++++++++++++++++------ src/apps/webpositive/BrowserWindow.h | 4 +++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index 33c347aa15..b0f8ce1d23 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -390,16 +390,21 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings, fFindTextControl = new BTextControl("find", "Find:", "", new BMessage(EDIT_FIND_NEXT)); fFindTextControl->SetModificationMessage(new BMessage(FIND_TEXT_CHANGED)); + fFindPreviousButton = new BButton("Previous", + new BMessage(EDIT_FIND_PREVIOUS)); + fFindNextButton = new BButton("Next", new BMessage(EDIT_FIND_NEXT)); + fFindCloseButton = new BButton("Close", + new BMessage(EDIT_HIDE_FIND_GROUP)); fFindCaseSensitiveCheckBox = new BCheckBox("Match case"); BView* findGroup = BGroupLayoutBuilder(B_VERTICAL) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) .Add(fFindTextControl) - .Add(new BButton("Previous", new BMessage(EDIT_FIND_PREVIOUS))) - .Add(new BButton("Next", new BMessage(EDIT_FIND_NEXT))) + .Add(fFindPreviousButton) + .Add(fFindNextButton) .Add(fFindCaseSensitiveCheckBox) .Add(BSpaceLayoutItem::CreateGlue()) - .Add(new BButton("Close", new BMessage(EDIT_HIDE_FIND_GROUP))) + .Add(fFindCloseButton) .SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing) ) @@ -538,11 +543,19 @@ BrowserWindow::DispatchMessage(BMessage* message, BHandler* target) // when the text control just goes out of focus. if (bytes[0] == B_RETURN) { // Do it in such a way that the user sees the Go-button go down. - fURLInputGroup->GoButton()->SetValue(B_CONTROL_ON); - UpdateIfNeeded(); - fURLInputGroup->GoButton()->Invoke(); - snooze(1000); - fURLInputGroup->GoButton()->SetValue(B_CONTROL_OFF); + _InvokeButtonVisibly(fURLInputGroup->GoButton()); + return; + } + } else if (target == fFindTextControl->TextView()) { + // Handle B_RETURN when the find text control has focus. + if (bytes[0] == B_RETURN) { + if ((modifiers & B_SHIFT_KEY) != 0) + _InvokeButtonVisibly(fFindPreviousButton); + else + _InvokeButtonVisibly(fFindNextButton); + return; + } else if (bytes[0] == B_ESCAPE) { + _InvokeButtonVisibly(fFindCloseButton); return; } } @@ -1978,6 +1991,17 @@ BrowserWindow::_ShowInterface(bool show) } +void +BrowserWindow::_InvokeButtonVisibly(BButton* button) +{ + button->SetValue(B_CONTROL_ON); + UpdateIfNeeded(); + button->Invoke(); + snooze(1000); + button->SetValue(B_CONTROL_OFF); +} + + BString BrowserWindow::_NewTabURL(bool isNewWindow) const { diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index 9e85994e51..4097bbcdac 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -187,6 +187,7 @@ private: void _SetAutoHideInterfaceInFullscreen(bool doIt); void _CheckAutoHideInterface(); void _ShowInterface(bool show); + void _InvokeButtonVisibly(BButton* button); BString _NewTabURL(bool isNewWindow) const; @@ -220,6 +221,9 @@ private: BLayoutItem* fToggleFullscreenButton; BTextControl* fFindTextControl; + BButton* fFindPreviousButton; + BButton* fFindNextButton; + BButton* fFindCloseButton; BCheckBox* fFindCaseSensitiveCheckBox; TabManager* fTabManager;