diff options
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser.cc | 66 | ||||
-rw-r--r-- | chrome/browser/browser.h | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.mm | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 1 | ||||
-rw-r--r-- | chrome/browser/location_bar.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/go_button.cc | 14 | ||||
-rw-r--r-- | chrome/browser/views/go_button.h | 10 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.h | 1 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 13 | ||||
-rw-r--r-- | chrome/test/test_location_bar.h | 1 | ||||
-rw-r--r-- | chrome/views/controls/button/custom_button.cc | 5 | ||||
-rw-r--r-- | chrome/views/controls/button/custom_button.h | 11 |
15 files changed, 110 insertions, 43 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 94cb54f..ccdb32d 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -1029,7 +1029,7 @@ void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) { tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, AUTOMATION_MSG_NAVIGATION_ERROR); - browser->GoBack(); + browser->GoBack(CURRENT_TAB); return; } } @@ -1048,7 +1048,7 @@ void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) { tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, AUTOMATION_MSG_NAVIGATION_ERROR); - browser->GoForward(); + browser->GoForward(CURRENT_TAB); return; } } diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index eecdd1a..5e1b4ca 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -551,7 +551,7 @@ void Browser::ShowSingleDOMUITab(const GURL& url) { /////////////////////////////////////////////////////////////////////////////// // Browser, Assorted browser commands: -void Browser::GoBack() { +void Browser::GoBack(WindowOpenDisposition disposition) { UserMetrics::RecordAction(L"Back", profile_); // If we are showing an interstitial, just hide it. @@ -565,14 +565,37 @@ void Browser::GoBack() { web_contents->interstitial_page()->DontProceed(); return; } - if (current_tab->controller()->CanGoBack()) - current_tab->controller()->GoBack(); + + if (current_tab->controller()->CanGoBack()) { + NavigationController* controller = 0; + if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB){ + controller = GetSelectedTabContents()->controller()->Clone(); + tabstrip_model_.AddTabContents( + controller->active_contents(), -1, + PageTransition::LINK, disposition == NEW_FOREGROUND_TAB); + } else { + // Default disposition is CURRENT_TAB. + controller = current_tab->controller(); + } + controller->GoBack(); + } } -void Browser::GoForward() { +void Browser::GoForward(WindowOpenDisposition disp) { UserMetrics::RecordAction(L"Forward", profile_); - if (GetSelectedTabContents()->controller()->CanGoForward()) - GetSelectedTabContents()->controller()->GoForward(); + if (GetSelectedTabContents()->controller()->CanGoForward()) { + NavigationController* controller = 0; + if (disp == NEW_FOREGROUND_TAB || disp == NEW_BACKGROUND_TAB) { + controller = GetSelectedTabContents()->controller()->Clone(); + tabstrip_model_.AddTabContents( + controller->active_contents(), -1, + PageTransition::LINK, disp == NEW_FOREGROUND_TAB); + } else { + // Default disposition is CURRENT_TAB. + controller = GetSelectedTabContents()->controller(); + } + controller->GoForward(); + } } void Browser::Reload() { @@ -597,11 +620,9 @@ void Browser::Reload() { } } -void Browser::Home() { +void Browser::Home(WindowOpenDisposition disposition) { UserMetrics::RecordAction(L"Home", profile_); - GURL homepage_url = GetHomePage(); - GetSelectedTabContents()->controller()->LoadURL( - homepage_url, GURL(), PageTransition::AUTO_BOOKMARK); + OpenURL(GetHomePage(), GURL(), disposition, PageTransition::AUTO_BOOKMARK); } void Browser::OpenCurrentURL() { @@ -612,9 +633,9 @@ void Browser::OpenCurrentURL() { location_bar->GetPageTransition()); } -void Browser::Go() { +void Browser::Go(WindowOpenDisposition disposition) { UserMetrics::RecordAction(L"Go", profile_); - window_->GetLocationBar()->AcceptInput(); + window_->GetLocationBar()->AcceptInputWithDisposition(disposition); } void Browser::Stop() { @@ -1095,10 +1116,8 @@ Browser* Browser::GetBrowserForController( return NULL; } -/////////////////////////////////////////////////////////////////////////////// -// Browser, CommandUpdater::CommandUpdaterDelegate implementation: - -void Browser::ExecuteCommand(int id) { +void Browser::ExecuteCommandWithDisposition( + int id, WindowOpenDisposition disposition) { // No commands are enabled if there is not yet any selected tab. // TODO(pkasting): It seems like we should not need this, because either // most/all commands should not have been enabled yet anyway or the ones that @@ -1115,12 +1134,12 @@ void Browser::ExecuteCommand(int id) { // declaration order in browser.h! switch (id) { // Navigation commands - case IDC_BACK: GoBack(); break; - case IDC_FORWARD: GoForward(); break; + case IDC_BACK: GoBack(disposition); break; + case IDC_FORWARD: GoForward(disposition); break; case IDC_RELOAD: Reload(); break; - case IDC_HOME: Home(); break; + case IDC_HOME: Home(disposition); break; case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; - case IDC_GO: Go(); break; + case IDC_GO: Go(disposition); break; case IDC_STOP: Stop(); break; // Window management commands @@ -1275,6 +1294,13 @@ void Browser::ExecuteCommand(int id) { } /////////////////////////////////////////////////////////////////////////////// +// Browser, CommandUpdater::CommandUpdaterDelegate implementation: + +void Browser::ExecuteCommand(int id) { + ExecuteCommandWithDisposition(id, CURRENT_TAB); +} + +/////////////////////////////////////////////////////////////////////////////// // Browser, TabStripModelDelegate implementation: GURL Browser::GetBlankTabURL() const { diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 17d11d7..bb91b29 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -249,12 +249,12 @@ class Browser : public TabStripModelDelegate, // how they appear in the GUI/menus (left to right, top to bottom, etc.). // Navigation commands - void GoBack(); - void GoForward(); + void GoBack(WindowOpenDisposition disposition); + void GoForward(WindowOpenDisposition disposition); void Reload(); - void Home(); + void Home(WindowOpenDisposition disposition); void OpenCurrentURL(); - void Go(); + void Go(WindowOpenDisposition disposition); void Stop(); // Window management commands void NewWindow(); @@ -361,6 +361,9 @@ class Browser : public TabStripModelDelegate, static Browser* GetBrowserForController( const NavigationController* controller, int* index); + // Calls ExecuteCommandWithDisposition with the given disposition. + void ExecuteCommandWithDisposition(int id, WindowOpenDisposition); + // Interface implementations //////////////////////////////////////////////// // Overridden from CommandUpdater::CommandUpdaterDelegate: diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm index 973e808..da73e17 100644 --- a/chrome/browser/cocoa/tab_contents_controller.mm +++ b/chrome/browser/cocoa/tab_contents_controller.mm @@ -65,6 +65,8 @@ class LocationBarBridge : public LocationBar { virtual PageTransition::Type GetPageTransition() const { NOTIMPLEMENTED(); return 0; } virtual void AcceptInput() { NOTIMPLEMENTED(); } + virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition) + { NOTIMPLEMENTED(); } virtual void FocusLocation(); virtual void FocusSearch() { NOTIMPLEMENTED(); } virtual void UpdateFeedIcon() { /* http://crbug.com/8832 */ } diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 9aa1bb6..860824b 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -149,7 +149,12 @@ PageTransition::Type LocationBarViewGtk::GetPageTransition() const { } void LocationBarViewGtk::AcceptInput() { - location_entry_->model()->AcceptInput(CURRENT_TAB, false); + AcceptInputWithDisposition(CURRENT_TAB); +} + +void LocationBarViewGtk::AcceptInputWithDisposition( + WindowOpenDisposition disposition) { + location_entry_->model()->AcceptInput(disposition, false); } void LocationBarViewGtk::FocusLocation() { diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index 2fc5b0b..8f4d017 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -59,6 +59,7 @@ class LocationBarViewGtk : public AutocompleteEditController, virtual WindowOpenDisposition GetWindowOpenDisposition() const; virtual PageTransition::Type GetPageTransition() const; virtual void AcceptInput(); + virtual void AcceptInputWithDisposition(WindowOpenDisposition); virtual void FocusLocation(); virtual void FocusSearch(); virtual void UpdateFeedIcon(); diff --git a/chrome/browser/location_bar.h b/chrome/browser/location_bar.h index b6499d8..a7b0c0d 100644 --- a/chrome/browser/location_bar.h +++ b/chrome/browser/location_bar.h @@ -37,6 +37,9 @@ class LocationBar { // Accepts the current string of text entered in the location bar. virtual void AcceptInput() = 0; + // Accept the current input, overriding the disposition. + virtual void AcceptInputWithDisposition(WindowOpenDisposition) = 0; + // Focuses and selects the contents of the location bar. virtual void FocusLocation() = 0; diff --git a/chrome/browser/views/go_button.cc b/chrome/browser/views/go_button.cc index db205c4..48773ae 100644 --- a/chrome/browser/views/go_button.cc +++ b/chrome/browser/views/go_button.cc @@ -5,7 +5,8 @@ #include "chrome/browser/views/go_button.h" #include "chrome/app/chrome_dll_resource.h" -#include "chrome/browser/command_updater.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/views/event_utils.h" #include "chrome/browser/views/location_bar_view.h" #include "chrome/common/l10n_util.h" #include "grit/generated_resources.h" @@ -13,16 +14,17 @@ //////////////////////////////////////////////////////////////////////////////// // GoButton, public: -GoButton::GoButton(LocationBarView* location_bar, - CommandUpdater* command_updater) +GoButton::GoButton(LocationBarView* location_bar, Browser* browser) : ToggleImageButton(this), location_bar_(location_bar), - command_updater_(command_updater), + browser_(browser), intended_mode_(MODE_GO), visible_mode_(MODE_GO), button_delay_(NULL), stop_timer_(this) { DCHECK(location_bar_); + set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | + views::Event::EF_MIDDLE_BUTTON_DOWN); } GoButton::~GoButton() { @@ -64,14 +66,14 @@ void GoButton::ScheduleChangeMode(Mode mode) { void GoButton::ButtonPressed(views::Button* button) { if (visible_mode_ == MODE_STOP) { - command_updater_->ExecuteCommand(IDC_STOP); + browser_->Stop(); // The user has clicked, so we can feel free to update the button, // even if the mouse is still hovering. ChangeMode(MODE_GO); } else if (visible_mode_ == MODE_GO && stop_timer_.empty()) { // If the go button is visible and not within the double click timer, go. - command_updater_->ExecuteCommand(IDC_GO); + browser_->Go(event_utils::DispositionFromEventFlags(mouse_event_flags())); // Figure out the system double-click time. if (button_delay_ == NULL) diff --git a/chrome/browser/views/go_button.h b/chrome/browser/views/go_button.h index c9d8252..a830191 100644 --- a/chrome/browser/views/go_button.h +++ b/chrome/browser/views/go_button.h @@ -8,7 +8,7 @@ #include "chrome/views/controls/button/image_button.h" #include "base/task.h" -class CommandUpdater; +class Browser; class LocationBarView; //////////////////////////////////////////////////////////////////////////////// @@ -26,9 +26,7 @@ class LocationBarView; class GoButton : public views::ToggleImageButton, public views::ButtonListener { public: - // TODO(beng): get rid of the command updater param and instead have a - // delegate. - GoButton(LocationBarView* location_bar, CommandUpdater* command_updater); + GoButton(LocationBarView* location_bar, Browser* Browser); virtual ~GoButton(); typedef enum Mode { MODE_GO = 0, MODE_STOP }; @@ -42,7 +40,7 @@ class GoButton : public views::ToggleImageButton, // Overridden from views::ButtonListener: virtual void ButtonPressed(views::Button* button); - + // Overridden from views::View: virtual void OnMouseExited(const views::MouseEvent& e); virtual bool GetTooltipText(int x, int y, std::wstring* tooltip); @@ -54,7 +52,7 @@ class GoButton : public views::ToggleImageButton, ScopedRunnableMethodFactory<GoButton> stop_timer_; LocationBarView* location_bar_; - CommandUpdater* command_updater_; + Browser* browser_; // The mode we should be in Mode intended_mode_; diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index 1bbc95c..2ece304 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -1082,6 +1082,10 @@ void LocationBarView::AcceptInput() { location_entry_->model()->AcceptInput(CURRENT_TAB, false); } +void LocationBarView::AcceptInputWithDisposition(WindowOpenDisposition disp) { + location_entry_->model()->AcceptInput(disp, false); +} + void LocationBarView::FocusLocation() { location_entry_->SetFocus(); location_entry_->SelectAll(true); diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index 920fc88..d0bcdb2 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -118,6 +118,7 @@ class LocationBarView : public LocationBar, virtual WindowOpenDisposition GetWindowOpenDisposition() const; virtual PageTransition::Type GetPageTransition() const; virtual void AcceptInput(); + virtual void AcceptInputWithDisposition(WindowOpenDisposition); virtual void FocusLocation(); virtual void FocusSearch(); virtual void UpdateFeedIcon(); diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 5695eac..78a8ae6 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -22,6 +22,7 @@ #include "chrome/browser/user_data_manager.h" #include "chrome/browser/views/bookmark_menu_button.h" #include "chrome/browser/views/dom_view.h" +#include "chrome/browser/views/event_utils.h" #include "chrome/browser/views/go_button.h" #include "chrome/browser/views/location_bar_view.h" #include "chrome/browser/views/theme_helpers.h" @@ -133,6 +134,8 @@ void BrowserToolbarView::CreateLeftSideControls() { ResourceBundle &rb = ResourceBundle::GetSharedInstance(); back_ = new views::ButtonDropDown(this, back_menu_model_.get()); + back_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | + views::Event::EF_MIDDLE_BUTTON_DOWN); back_->set_tag(IDC_BACK); back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, views::ImageButton::ALIGN_TOP); @@ -148,6 +151,8 @@ void BrowserToolbarView::CreateLeftSideControls() { AddChildView(back_); forward_ = new views::ButtonDropDown(this, forward_menu_model_.get()); + forward_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | + views::Event::EF_MIDDLE_BUTTON_DOWN); forward_->set_tag(IDC_FORWARD); forward_->SetImage(views::CustomButton::BS_NORMAL, rb.GetBitmapNamed(IDR_FORWARD)); @@ -176,6 +181,8 @@ void BrowserToolbarView::CreateLeftSideControls() { AddChildView(reload_); home_ = new views::ImageButton(this); + home_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | + views::Event::EF_MIDDLE_BUTTON_DOWN); home_->set_tag(IDC_HOME); home_->SetImage(views::CustomButton::BS_NORMAL, rb.GetBitmapNamed(IDR_HOME)); home_->SetImage(views::CustomButton::BS_HOT, rb.GetBitmapNamed(IDR_HOME_H)); @@ -218,7 +225,7 @@ void BrowserToolbarView::CreateCenterStack(Profile *profile) { location_bar_->Init(); // The Go button. - go_ = new GoButton(location_bar_, browser_->command_updater()); + go_ = new GoButton(location_bar_, browser_); go_->SetImage(views::CustomButton::BS_NORMAL, rb.GetBitmapNamed(IDR_GO)); go_->SetImage(views::CustomButton::BS_HOT, rb.GetBitmapNamed(IDR_GO_H)); go_->SetImage(views::CustomButton::BS_PUSHED, rb.GetBitmapNamed(IDR_GO_P)); @@ -832,7 +839,9 @@ void BrowserToolbarView::EnabledStateChangedForCommand(int id, bool enabled) { } void BrowserToolbarView::ButtonPressed(views::Button* sender) { - browser_->ExecuteCommand(sender->tag()); + browser_->ExecuteCommandWithDisposition( + sender->tag(), + event_utils::DispositionFromEventFlags(sender->mouse_event_flags())); } // static diff --git a/chrome/test/test_location_bar.h b/chrome/test/test_location_bar.h index b303a737..29ba999 100644 --- a/chrome/test/test_location_bar.h +++ b/chrome/test/test_location_bar.h @@ -34,6 +34,7 @@ class TestLocationBar : public LocationBar { } virtual PageTransition::Type GetPageTransition() const { return transition_; } virtual void AcceptInput() {} + virtual void AcceptInputWithDisposition(WindowOpenDisposition) {}; virtual void FocusLocation() {} virtual void FocusSearch() {} virtual void UpdateFeedIcon() {} diff --git a/chrome/views/controls/button/custom_button.cc b/chrome/views/controls/button/custom_button.cc index a01c0ab..4193918 100644 --- a/chrome/views/controls/button/custom_button.cc +++ b/chrome/views/controls/button/custom_button.cc @@ -82,13 +82,14 @@ bool CustomButton::IsFocusable() const { CustomButton::CustomButton(ButtonListener* listener) : Button(listener), state_(BS_NORMAL), - animate_on_state_change_(true) { + animate_on_state_change_(true), + triggerable_event_flags_(MouseEvent::EF_LEFT_BUTTON_DOWN) { hover_animation_.reset(new ThrobAnimation(this)); hover_animation_->SetSlideDuration(kHoverFadeDurationMs); } bool CustomButton::IsTriggerableEvent(const MouseEvent& e) { - return e.IsLeftMouseButton(); + return (triggerable_event_flags_ & e.GetFlags()) != 0; } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/views/controls/button/custom_button.h b/chrome/views/controls/button/custom_button.h index cb4db5d..db0bc9e 100644 --- a/chrome/views/controls/button/custom_button.h +++ b/chrome/views/controls/button/custom_button.h @@ -43,6 +43,14 @@ class CustomButton : public Button, virtual bool IsEnabled() const; virtual bool IsFocusable() const; + void set_triggerable_event_flags(int triggerable_event_flags) { + triggerable_event_flags_ = triggerable_event_flags; + } + + int triggerable_event_flags() const { + return triggerable_event_flags_; + } + protected: // Construct the Button with a Listener. See comment for Button's ctor. explicit CustomButton(ButtonListener* listener); @@ -86,6 +94,9 @@ class CustomButton : public Button, // throbbing. bool animate_on_state_change_; + // Mouse event flags which can trigger button actions. + int triggerable_event_flags_; + DISALLOW_COPY_AND_ASSIGN(CustomButton); }; |