diff options
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 18 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_star_toggle.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_star_toggle.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 916 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.h | 143 |
6 files changed, 548 insertions, 541 deletions
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 7adbbc5..18f80a4 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -379,8 +379,8 @@ void BrowserView::WindowMoved() { browser::HideBookmarkBubbleView(); // Close the omnibox popup, if any. - if (toolbar_->GetLocationBarView()) - toolbar_->GetLocationBarView()->location_entry()->ClosePopup(); + if (toolbar_->location_bar()) + toolbar_->location_bar()->location_entry()->ClosePopup(); } void BrowserView::WindowMoveOrResizeStarted() { @@ -708,7 +708,7 @@ void BrowserView::SetFullscreen(bool fullscreen) { // * Ignoring all intervening Layout() calls, which resize the webpage and // thus are slow and look ugly ignore_layout_ = true; - LocationBarView* location_bar = toolbar_->GetLocationBarView(); + LocationBarView* location_bar = toolbar_->location_bar(); AutocompleteEditViewWin* edit_view = static_cast<AutocompleteEditViewWin*>(location_bar->location_entry()); if (IsFullscreen()) { @@ -763,11 +763,11 @@ bool BrowserView::IsFullscreen() const { } LocationBar* BrowserView::GetLocationBar() const { - return toolbar_->GetLocationBarView(); + return toolbar_->location_bar(); } void BrowserView::SetFocusToLocationBar() { - LocationBarView* location_bar = toolbar_->GetLocationBarView(); + LocationBarView* location_bar = toolbar_->location_bar(); if (location_bar->IsFocusable()) { location_bar->FocusLocation(); } else { @@ -778,7 +778,7 @@ void BrowserView::SetFocusToLocationBar() { } void BrowserView::UpdateStopGoState(bool is_loading, bool force) { - toolbar_->GetGoButton()->ChangeMode( + toolbar_->go_button()->ChangeMode( is_loading ? GoButton::MODE_STOP : GoButton::MODE_GO, force); } @@ -945,7 +945,7 @@ BookmarkBarView* BrowserView::GetBookmarkBarView() const { } LocationBarView* BrowserView::GetLocationBarView() const { - return toolbar_->GetLocationBarView(); + return toolbar_->location_bar(); } /////////////////////////////////////////////////////////////////////////////// @@ -1356,7 +1356,7 @@ void BrowserView::Init() { AddChildView(tabstrip_); frame_->TabStripCreated(tabstrip_); - toolbar_ = new BrowserToolbarView(browser_.get()); + toolbar_ = new ToolbarView(browser_.get()); AddChildView(toolbar_); toolbar_->SetID(VIEW_ID_TOOLBAR); toolbar_->Init(browser_->profile()); @@ -1422,7 +1422,7 @@ int BrowserView::LayoutTabStrip() { int BrowserView::LayoutToolbar(int top) { int browser_view_width = width(); bool visible = IsToolbarVisible(); - toolbar_->GetLocationBarView()->SetFocusable(visible); + toolbar_->location_bar()->SetFocusable(visible); int y = top - ((visible && IsTabStripVisible()) ? kToolbarTabStripVerticalOverlap : 0); int height = visible ? toolbar_->GetPreferredSize().height() : 0; diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 98d1e56..3b15d55 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -27,7 +27,6 @@ class BookmarkBarView; class Browser; class BrowserBubble; -class BrowserToolbarView; class DownloadShelfView; class EncodingMenuControllerDelegate; class ExtensionShelf; @@ -37,6 +36,7 @@ class InfoBarContainer; class StatusBubbleViews; class TabContentsContainer; class TabStrip; +class ToolbarView; namespace views { class Menu; @@ -368,7 +368,7 @@ class BrowserView : public BrowserWindow, TabStrip* tabstrip_; // The Toolbar containing the navigation buttons, menus and the address bar. - BrowserToolbarView* toolbar_; + ToolbarView* toolbar_; // The Bookmark Bar View for this window. Lazily created. scoped_ptr<BookmarkBarView> bookmark_bar_view_; diff --git a/chrome/browser/views/toolbar_star_toggle.cc b/chrome/browser/views/toolbar_star_toggle.cc index 252cc83..8c89a5a 100644 --- a/chrome/browser/views/toolbar_star_toggle.cc +++ b/chrome/browser/views/toolbar_star_toggle.cc @@ -28,7 +28,7 @@ using base::TimeTicks; static const int64 kDisallowClickMS = 40; ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* listener, - BrowserToolbarView* host) + ToolbarView* host) : ToggleImageButton(listener), host_(host), ignore_click_(false) { diff --git a/chrome/browser/views/toolbar_star_toggle.h b/chrome/browser/views/toolbar_star_toggle.h index f63cffc7..37c2db5 100644 --- a/chrome/browser/views/toolbar_star_toggle.h +++ b/chrome/browser/views/toolbar_star_toggle.h @@ -9,8 +9,8 @@ #include "chrome/browser/views/info_bubble.h" #include "views/controls/button/image_button.h" -class BrowserToolbarView; class GURL; +class ToolbarView; // ToolbarStarToggle is used for the star button on the toolbar, allowing the // user to star the current page. ToolbarStarToggle manages showing the @@ -19,7 +19,7 @@ class GURL; class ToolbarStarToggle : public views::ToggleImageButton, public InfoBubbleDelegate { public: - ToolbarStarToggle(views::ButtonListener* listener, BrowserToolbarView* host); + ToolbarStarToggle(views::ButtonListener* listener, ToolbarView* host); // If the bubble isn't showing, shows it. void ShowStarBubble(const GURL& url, bool newly_bookmarked); @@ -46,7 +46,7 @@ class ToolbarStarToggle : public views::ToggleImageButton, virtual bool CloseOnEscape(); // Contains us. - BrowserToolbarView* host_; + ToolbarView* host_; // Time the bubble last closed. base::TimeTicks bubble_closed_time_; diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index fd29674..00de1f4 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -80,7 +80,10 @@ static const int kOmniboxButtonsHorizontalMargin = 2; static SkBitmap* kPopupBackgroundEdge = NULL; -BrowserToolbarView::BrowserToolbarView(Browser* browser) +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, public: + +ToolbarView::ToolbarView(Browser* browser) : EncodingMenuControllerDelegate(browser), model_(browser->toolbar_model()), acc_focused_view_(NULL), @@ -119,11 +122,11 @@ BrowserToolbarView::BrowserToolbarView(Browser* browser) } } -BrowserToolbarView::~BrowserToolbarView() { +ToolbarView::~ToolbarView() { profiles_helper_->OnDelegateDeleted(); } -void BrowserToolbarView::Init(Profile* profile) { +void ToolbarView::Init(Profile* profile) { // Create all the individual Views in the Toolbar. CreateLeftSideControls(); CreateCenterStack(profile); @@ -134,7 +137,7 @@ void BrowserToolbarView::Init(Profile* profile) { SetProfile(profile); } -void BrowserToolbarView::SetProfile(Profile* profile) { +void ToolbarView::SetProfile(Profile* profile) { if (profile == profile_) return; @@ -142,209 +145,243 @@ void BrowserToolbarView::SetProfile(Profile* profile) { location_bar_->SetProfile(profile); } -void BrowserToolbarView::CreateLeftSideControls() { - 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); - back_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_BACK)); - back_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_BACK)); - back_->SetID(VIEW_ID_BACK_BUTTON); - - 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_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_FORWARD)); - forward_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_FORWARD)); - forward_->SetID(VIEW_ID_FORWARD_BUTTON); +void ToolbarView::Update(TabContents* tab, bool should_restore_state) { + tab_ = tab; + if (location_bar_) + location_bar_->Update(should_restore_state ? tab : NULL); +} - reload_ = new views::ImageButton(this); - reload_->set_tag(IDC_RELOAD); - reload_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_RELOAD)); - reload_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RELOAD)); - reload_->SetID(VIEW_ID_RELOAD_BUTTON); +int ToolbarView::GetNextAccessibleViewIndex(int view_index, bool nav_left) { + int modifier = 1; - 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_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_HOME)); - home_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_HOME)); - home_->SetID(VIEW_ID_HOME_BUTTON); + if (nav_left) + modifier = -1; - LoadLeftSideControlsImages(); + int current_view_index = view_index + modifier; - AddChildView(back_); - AddChildView(forward_); - AddChildView(reload_); - AddChildView(home_); + while ((current_view_index >= 0) && + (current_view_index < GetChildViewCount())) { + // Skip the location bar, as it has its own keyboard navigation. Also skip + // any views that cannot be interacted with. + if (current_view_index == GetChildIndex(location_bar_) || + !GetChildViewAt(current_view_index)->IsEnabled() || + !GetChildViewAt(current_view_index)->IsVisible()) { + current_view_index += modifier; + continue; + } + // Update view_index with the available button index found. + view_index = current_view_index; + break; + } + // Returns the next available button index, or if no button is available in + // the specified direction, remains where it was. + return view_index; } -void BrowserToolbarView::CreateCenterStack(Profile *profile) { - star_ = new ToolbarStarToggle(this, this); - star_->set_tag(IDC_STAR); - star_->SetDragController(this); - star_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_STAR)); - star_->SetToggledTooltipText(l10n_util::GetString(IDS_TOOLTIP_STARRED)); - star_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_STAR)); - star_->SetID(VIEW_ID_STAR_BUTTON); - AddChildView(star_); - - location_bar_ = new LocationBarView(profile, browser_->command_updater(), - model_, this, - display_mode_ == DISPLAYMODE_LOCATION, - this); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, EncodingMenuControllerDelegate implementation: - // The Go button. - go_ = new GoButton(location_bar_, browser_); - go_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_GO)); - go_->SetID(VIEW_ID_GO_BUTTON); +bool ToolbarView::IsItemChecked(int id) const { + if (!profile_) + return false; + if (id == IDC_SHOW_BOOKMARK_BAR) + return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); + return EncodingMenuControllerDelegate::IsItemChecked(id); +} - LoadCenterStackImages(); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, Menu::BaseControllerDelegate overrides: - AddChildView(location_bar_); - location_bar_->Init(); - AddChildView(go_); +bool ToolbarView::GetAcceleratorInfo(int id, views::Accelerator* accel) { + // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators + // anywhere so we need to check for them explicitly here. + // TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings. + switch (id) { + case IDC_CUT: + *accel = views::Accelerator(L'X', false, true, false); + return true; + case IDC_COPY: + *accel = views::Accelerator(L'C', false, true, false); + return true; + case IDC_PASTE: + *accel = views::Accelerator(L'V', false, true, false); + return true; + } + // Else, we retrieve the accelerator information from the frame. + return GetWidget()->GetAccelerator(id, accel); } -void BrowserToolbarView::CreateRightSideControls(Profile* profile) { - page_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); - page_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_PAGE)); - page_menu_->SetTooltipText(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP)); - page_menu_->SetID(VIEW_ID_PAGE_MENU); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, views::MenuDelegate implementation: +void ToolbarView::RunMenu(views::View* source, const gfx::Point& pt, + gfx::NativeView parent) { + switch (source->GetID()) { + case VIEW_ID_PAGE_MENU: + RunPageMenu(pt, parent); + break; + case VIEW_ID_APP_MENU: + RunAppMenu(pt, parent); + break; + default: + NOTREACHED() << "Invalid source menu."; + } +} - app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); - app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); - app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, - l10n_util::GetString(IDS_PRODUCT_NAME))); - app_menu_->SetID(VIEW_ID_APP_MENU); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, GetProfilesHelper::Delegate implementation: - LoadRightSideControlsImages(); +void ToolbarView::OnGetProfilesDone( + const std::vector<std::wstring>& profiles) { + // Nothing to do if the menu has gone away. + if (!profiles_menu_) + return; - AddChildView(page_menu_); - AddChildView(app_menu_); + // Store the latest list of profiles in the browser. + browser_->set_user_data_dir_profiles(profiles); - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kBookmarkMenu)) { - bookmark_menu_ = new BookmarkMenuButton(browser_); - AddChildView(bookmark_menu_); - } else { - bookmark_menu_ = NULL; + // Add direct sub menu items for profiles. + std::vector<std::wstring>::const_iterator iter = profiles.begin(); + for (int i = IDC_NEW_WINDOW_PROFILE_0; + (i <= IDC_NEW_WINDOW_PROFILE_LAST) && (iter != profiles.end()); + ++i, ++iter) + profiles_menu_->AppendMenuItemWithLabel(i, *iter); + + // If there are more profiles then show "Other" link. + if (iter != profiles.end()) { + profiles_menu_->AppendSeparator(); + profiles_menu_->AppendMenuItemWithLabel( + IDC_SELECT_PROFILE, l10n_util::GetString(IDS_SELECT_PROFILE)); } + + // Always show a link to select a new profile. + profiles_menu_->AppendSeparator(); + profiles_menu_->AppendMenuItemWithLabel( + IDC_NEW_PROFILE, + l10n_util::GetString(IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY)); } -void BrowserToolbarView::LoadLeftSideControlsImages() { - ThemeProvider* tp = GetThemeProvider(); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, LocationBarView::Delegate implementation: - SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); - SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); +TabContents* ToolbarView::GetTabContents() { + return tab_; +} - back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK)); - back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H)); - back_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_BACK_P)); - back_->SetImage(views::CustomButton::BS_DISABLED, - tp->GetBitmapNamed(IDR_BACK_D)); - back_->SetBackground(color, background, - tp->GetBitmapNamed(IDR_BACK_MASK)); +void ToolbarView::OnInputInProgress(bool in_progress) { + // The edit should make sure we're only notified when something changes. + DCHECK(model_->input_in_progress() != in_progress); - forward_->SetImage(views::CustomButton::BS_NORMAL, - tp->GetBitmapNamed(IDR_FORWARD)); - forward_->SetImage(views::CustomButton::BS_HOT, - tp->GetBitmapNamed(IDR_FORWARD_H)); - forward_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_FORWARD_P)); - forward_->SetImage(views::CustomButton::BS_DISABLED, - tp->GetBitmapNamed(IDR_FORWARD_D)); - forward_->SetBackground(color, background, - tp->GetBitmapNamed(IDR_FORWARD_MASK)); + model_->set_input_in_progress(in_progress); + location_bar_->Update(NULL); +} - reload_->SetImage(views::CustomButton::BS_NORMAL, - tp->GetBitmapNamed(IDR_RELOAD)); - reload_->SetImage(views::CustomButton::BS_HOT, - tp->GetBitmapNamed(IDR_RELOAD_H)); - reload_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_RELOAD_P)); - reload_->SetBackground(color, background, - tp->GetBitmapNamed(IDR_BUTTON_MASK)); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, CommandUpdater::CommandObserver implementation: - home_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_HOME)); - home_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_HOME_H)); - home_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_HOME_P)); - home_->SetBackground(color, background, - tp->GetBitmapNamed(IDR_BUTTON_MASK)); +void ToolbarView::EnabledStateChangedForCommand(int id, bool enabled) { + views::Button* button = NULL; + switch (id) { + case IDC_BACK: + button = back_; + break; + case IDC_FORWARD: + button = forward_; + break; + case IDC_RELOAD: + button = reload_; + break; + case IDC_HOME: + button = home_; + break; + case IDC_STAR: + button = star_; + break; + } + if (button) + button->SetEnabled(enabled); } -void BrowserToolbarView::LoadCenterStackImages() { - ThemeProvider* tp = GetThemeProvider(); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, views::Button::ButtonListener implementation: - SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); - SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); +void ToolbarView::ButtonPressed(views::Button* sender) { + browser_->ExecuteCommandWithDisposition( + sender->tag(), + event_utils::DispositionFromEventFlags(sender->mouse_event_flags())); +} - star_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_STAR)); - star_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_STAR_H)); - star_->SetImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_STAR_P)); - star_->SetImage(views::CustomButton::BS_DISABLED, - tp->GetBitmapNamed(IDR_STAR_D)); - star_->SetToggledImage(views::CustomButton::BS_NORMAL, - tp->GetBitmapNamed(IDR_STARRED)); - star_->SetToggledImage(views::CustomButton::BS_HOT, - tp->GetBitmapNamed(IDR_STARRED_H)); - star_->SetToggledImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_STARRED_P)); - star_->SetBackground(color, background, - tp->GetBitmapNamed(IDR_STAR_MASK)); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, AutocompletePopupPositioner implementation: - go_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_GO)); - go_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_GO_H)); - go_->SetImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_GO_P)); - go_->SetToggledImage(views::CustomButton::BS_NORMAL, - tp->GetBitmapNamed(IDR_STOP)); - go_->SetToggledImage(views::CustomButton::BS_HOT, - tp->GetBitmapNamed(IDR_STOP_H)); - go_->SetToggledImage(views::CustomButton::BS_PUSHED, - tp->GetBitmapNamed(IDR_STOP_P)); - go_->SetBackground(color, background, - tp->GetBitmapNamed(IDR_GO_MASK)); +gfx::Rect ToolbarView::GetPopupBounds() const { + gfx::Point origin; + views::View::ConvertPointToScreen(star_, &origin); + origin.set_y(origin.y() + star_->height() + kOmniboxPopupVerticalSpacing); + gfx::Rect popup_bounds(origin.x(), origin.y(), + star_->width() + location_bar_->width() + go_->width(), + 0); + if (UILayoutIsRightToLeft()) { + popup_bounds.set_x( + popup_bounds.x() - location_bar_->width() - go_->width()); + } else { + popup_bounds.set_x(popup_bounds.x()); + } + popup_bounds.set_y(popup_bounds.y()); + popup_bounds.set_width(popup_bounds.width()); + // Inset the bounds a little, since the buttons on either edge of the omnibox + // have invisible padding that makes the popup appear too wide. + popup_bounds.Inset(kOmniboxButtonsHorizontalMargin, 0); + return popup_bounds; } -void BrowserToolbarView::LoadRightSideControlsImages() { - ThemeProvider* tp = GetThemeProvider(); +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, NotificationObserver implementation: - // We use different menu button images if the locale is right-to-left. - if (UILayoutIsRightToLeft()) - page_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_PAGE_RTL)); - else - page_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_PAGE)); - if (UILayoutIsRightToLeft()) - app_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_CHROME_RTL)); - else - app_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_CHROME)); +void ToolbarView::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NotificationType::PREF_CHANGED) { + std::wstring* pref_name = Details<std::wstring>(details).ptr(); + if (*pref_name == prefs::kShowHomeButton) { + Layout(); + SchedulePaint(); + } + } } -void BrowserToolbarView::Update(TabContents* tab, bool should_restore_state) { - tab_ = tab; +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, views::View overrides: - if (!location_bar_) - return; +gfx::Size ToolbarView::GetPreferredSize() { + if (IsDisplayModeNormal()) { + int min_width = kControlIndent + back_->GetPreferredSize().width() + + forward_->GetPreferredSize().width() + kControlHorizOffset + + reload_->GetPreferredSize().width() + (show_home_button_.GetValue() ? + (home_->GetPreferredSize().width() + kControlHorizOffset) : 0) + + star_->GetPreferredSize().width() + go_->GetPreferredSize().width() + + kMenuButtonOffset + + (bookmark_menu_ ? bookmark_menu_->GetPreferredSize().width() : 0) + + page_menu_->GetPreferredSize().width() + + app_menu_->GetPreferredSize().width() + kPaddingRight; - location_bar_->Update(should_restore_state ? tab : NULL); -} + static SkBitmap normal_background; + if (normal_background.isNull()) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); + } -void BrowserToolbarView::OnInputInProgress(bool in_progress) { - // The edit should make sure we're only notified when something changes. - DCHECK(model_->input_in_progress() != in_progress); + return gfx::Size(min_width, normal_background.height()); + } - model_->set_input_in_progress(in_progress); - location_bar_->Update(NULL); + int vertical_spacing = PopupTopSpacing() + + (GetWindow()->GetNonClientView()->UseNativeFrame() ? + kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); + return gfx::Size(0, location_bar_->GetPreferredSize().height() + + vertical_spacing); } -void BrowserToolbarView::Layout() { +void ToolbarView::Layout() { // If we have not been initialized yet just do nothing. if (back_ == NULL) return; @@ -423,7 +460,7 @@ void BrowserToolbarView::Layout() { app_menu_->SetBounds(next_menu_x, child_y, app_menu_width, child_height); } -void BrowserToolbarView::Paint(gfx::Canvas* canvas) { +void ToolbarView::Paint(gfx::Canvas* canvas) { View::Paint(canvas); if (IsDisplayModeNormal()) @@ -445,7 +482,18 @@ void BrowserToolbarView::Paint(gfx::Canvas* canvas) { canvas->FillRectInt(SK_ColorBLACK, 0, height() - 1, width(), 1); } -void BrowserToolbarView::DidGainFocus() { +void ToolbarView::ThemeChanged() { + LoadLeftSideControlsImages(); + LoadCenterStackImages(); + LoadRightSideControlsImages(); +} + +void ToolbarView::ShowContextMenu(int x, int y, bool is_mouse_gesture) { + if (acc_focused_view_) + acc_focused_view_->ShowContextMenu(x, y, is_mouse_gesture); +} + +void ToolbarView::DidGainFocus() { #if defined(OS_WIN) // Check to see if MSAA focus should be restored to previously focused button, // and if button is an enabled, visibled child of toolbar. @@ -489,7 +537,7 @@ void BrowserToolbarView::DidGainFocus() { #endif } -void BrowserToolbarView::WillLoseFocus() { +void ToolbarView::WillLoseFocus() { #if defined(OS_WIN) if (acc_focused_view_) { // Resetting focus state. @@ -504,7 +552,7 @@ void BrowserToolbarView::WillLoseFocus() { #endif } -bool BrowserToolbarView::OnKeyPressed(const views::KeyEvent& e) { +bool ToolbarView::OnKeyPressed(const views::KeyEvent& e) { #if defined(OS_WIN) // Paranoia check, button should be initialized upon toolbar gaining focus. if (!acc_focused_view_) @@ -580,7 +628,7 @@ bool BrowserToolbarView::OnKeyPressed(const views::KeyEvent& e) { return false; } -bool BrowserToolbarView::OnKeyReleased(const views::KeyEvent& e) { +bool ToolbarView::OnKeyReleased(const views::KeyEvent& e) { // Paranoia check, button should be initialized upon toolbar gaining focus. if (!acc_focused_view_) return false; @@ -589,36 +637,264 @@ bool BrowserToolbarView::OnKeyReleased(const views::KeyEvent& e) { return acc_focused_view_->OnKeyReleased(e); } -gfx::Size BrowserToolbarView::GetPreferredSize() { - if (IsDisplayModeNormal()) { - int min_width = kControlIndent + back_->GetPreferredSize().width() + - forward_->GetPreferredSize().width() + kControlHorizOffset + - reload_->GetPreferredSize().width() + (show_home_button_.GetValue() ? - (home_->GetPreferredSize().width() + kControlHorizOffset) : 0) + - star_->GetPreferredSize().width() + go_->GetPreferredSize().width() + - kMenuButtonOffset + - (bookmark_menu_ ? bookmark_menu_->GetPreferredSize().width() : 0) + - page_menu_->GetPreferredSize().width() + - app_menu_->GetPreferredSize().width() + kPaddingRight; +bool ToolbarView::GetAccessibleName(std::wstring* name) { + if (!accessible_name_.empty()) { + (*name).assign(accessible_name_); + return true; + } + return false; +} - static SkBitmap normal_background; - if (normal_background.isNull()) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); +bool ToolbarView::GetAccessibleRole(AccessibilityTypes::Role* role) { + DCHECK(role); + + *role = AccessibilityTypes::ROLE_TOOLBAR; + return true; +} + +void ToolbarView::SetAccessibleName(const std::wstring& name) { + accessible_name_.assign(name); +} + +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, private: + +int ToolbarView::PopupTopSpacing() const { + return GetWindow()->GetNonClientView()->UseNativeFrame() ? + 0 : kPopupTopSpacingNonGlass; +} + +void ToolbarView::WriteDragData(views::View* sender, + int press_x, + int press_y, + OSExchangeData* data) { + DCHECK( + GetDragOperations(sender, press_x, press_y) != DragDropTypes::DRAG_NONE); + + UserMetrics::RecordAction(L"Toolbar_DragStar", profile_); + +#if defined(OS_WIN) + // If there is a bookmark for the URL, add the bookmark drag data for it. We + // do this to ensure the bookmark is moved, rather than creating an new + // bookmark. + if (profile_ && profile_->GetBookmarkModel()) { + BookmarkNode* node = profile_->GetBookmarkModel()-> + GetMostRecentlyAddedNodeForURL(tab_->GetURL()); + if (node) { + BookmarkDragData bookmark_data(node); + bookmark_data.Write(profile_, data); } + } - return gfx::Size(min_width, normal_background.height()); + drag_utils::SetURLAndDragImage(tab_->GetURL(), + UTF16ToWideHack(tab_->GetTitle()), + tab_->GetFavIcon(), + data); +#else + // TODO(port): do bookmark item drag & drop + NOTIMPLEMENTED(); +#endif +} + +int ToolbarView::GetDragOperations(views::View* sender, int x, int y) { + DCHECK(sender == star_); + if (!tab_ || !tab_->ShouldDisplayURL() || !tab_->GetURL().is_valid()) { + return DragDropTypes::DRAG_NONE; + } + if (profile_ && profile_->GetBookmarkModel() && + profile_->GetBookmarkModel()->IsBookmarked(tab_->GetURL())) { + return DragDropTypes::DRAG_MOVE | DragDropTypes::DRAG_COPY | + DragDropTypes::DRAG_LINK; } + return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK; +} - int vertical_spacing = PopupTopSpacing() + - (GetWindow()->GetNonClientView()->UseNativeFrame() ? - kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); - return gfx::Size(0, location_bar_->GetPreferredSize().height() + - vertical_spacing); +void ToolbarView::CreateLeftSideControls() { + 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); + back_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_BACK)); + back_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_BACK)); + back_->SetID(VIEW_ID_BACK_BUTTON); + + 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_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_FORWARD)); + forward_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_FORWARD)); + forward_->SetID(VIEW_ID_FORWARD_BUTTON); + + reload_ = new views::ImageButton(this); + reload_->set_tag(IDC_RELOAD); + reload_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_RELOAD)); + reload_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RELOAD)); + reload_->SetID(VIEW_ID_RELOAD_BUTTON); + + 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_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_HOME)); + home_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_HOME)); + home_->SetID(VIEW_ID_HOME_BUTTON); + + LoadLeftSideControlsImages(); + + AddChildView(back_); + AddChildView(forward_); + AddChildView(reload_); + AddChildView(home_); +} + +void ToolbarView::CreateCenterStack(Profile *profile) { + star_ = new ToolbarStarToggle(this, this); + star_->set_tag(IDC_STAR); + star_->SetDragController(this); + star_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_STAR)); + star_->SetToggledTooltipText(l10n_util::GetString(IDS_TOOLTIP_STARRED)); + star_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_STAR)); + star_->SetID(VIEW_ID_STAR_BUTTON); + AddChildView(star_); + + location_bar_ = new LocationBarView(profile, browser_->command_updater(), + model_, this, + display_mode_ == DISPLAYMODE_LOCATION, + this); + + // The Go button. + go_ = new GoButton(location_bar_, browser_); + go_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_GO)); + go_->SetID(VIEW_ID_GO_BUTTON); + + LoadCenterStackImages(); + + AddChildView(location_bar_); + location_bar_->Init(); + AddChildView(go_); +} + +void ToolbarView::CreateRightSideControls(Profile* profile) { + page_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); + page_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_PAGE)); + page_menu_->SetTooltipText(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP)); + page_menu_->SetID(VIEW_ID_PAGE_MENU); + + + app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); + app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); + app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, + l10n_util::GetString(IDS_PRODUCT_NAME))); + app_menu_->SetID(VIEW_ID_APP_MENU); + + LoadRightSideControlsImages(); + + AddChildView(page_menu_); + AddChildView(app_menu_); + + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kBookmarkMenu)) { + bookmark_menu_ = new BookmarkMenuButton(browser_); + AddChildView(bookmark_menu_); + } else { + bookmark_menu_ = NULL; + } +} + +void ToolbarView::LoadLeftSideControlsImages() { + ThemeProvider* tp = GetThemeProvider(); + + SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); + SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); + + back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK)); + back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H)); + back_->SetImage(views::CustomButton::BS_PUSHED, + tp->GetBitmapNamed(IDR_BACK_P)); + back_->SetImage(views::CustomButton::BS_DISABLED, + tp->GetBitmapNamed(IDR_BACK_D)); + back_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_BACK_MASK)); + + forward_->SetImage(views::CustomButton::BS_NORMAL, + tp->GetBitmapNamed(IDR_FORWARD)); + forward_->SetImage(views::CustomButton::BS_HOT, + tp->GetBitmapNamed(IDR_FORWARD_H)); + forward_->SetImage(views::CustomButton::BS_PUSHED, + tp->GetBitmapNamed(IDR_FORWARD_P)); + forward_->SetImage(views::CustomButton::BS_DISABLED, + tp->GetBitmapNamed(IDR_FORWARD_D)); + forward_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_FORWARD_MASK)); + + reload_->SetImage(views::CustomButton::BS_NORMAL, + tp->GetBitmapNamed(IDR_RELOAD)); + reload_->SetImage(views::CustomButton::BS_HOT, + tp->GetBitmapNamed(IDR_RELOAD_H)); + reload_->SetImage(views::CustomButton::BS_PUSHED, + tp->GetBitmapNamed(IDR_RELOAD_P)); + reload_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_BUTTON_MASK)); + + home_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_HOME)); + home_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_HOME_H)); + home_->SetImage(views::CustomButton::BS_PUSHED, + tp->GetBitmapNamed(IDR_HOME_P)); + home_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_BUTTON_MASK)); } -void BrowserToolbarView::RunPageMenu(const gfx::Point& pt, - gfx::NativeView parent) { +void ToolbarView::LoadCenterStackImages() { + ThemeProvider* tp = GetThemeProvider(); + + SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); + SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); + + star_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_STAR)); + star_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_STAR_H)); + star_->SetImage(views::CustomButton::BS_PUSHED, + tp->GetBitmapNamed(IDR_STAR_P)); + star_->SetImage(views::CustomButton::BS_DISABLED, + tp->GetBitmapNamed(IDR_STAR_D)); + star_->SetToggledImage(views::CustomButton::BS_NORMAL, + tp->GetBitmapNamed(IDR_STARRED)); + star_->SetToggledImage(views::CustomButton::BS_HOT, + tp->GetBitmapNamed(IDR_STARRED_H)); + star_->SetToggledImage(views::CustomButton::BS_PUSHED, + tp->GetBitmapNamed(IDR_STARRED_P)); + star_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_STAR_MASK)); + + go_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_GO)); + go_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_GO_H)); + go_->SetImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_GO_P)); + go_->SetToggledImage(views::CustomButton::BS_NORMAL, + tp->GetBitmapNamed(IDR_STOP)); + go_->SetToggledImage(views::CustomButton::BS_HOT, + tp->GetBitmapNamed(IDR_STOP_H)); + go_->SetToggledImage(views::CustomButton::BS_PUSHED, + tp->GetBitmapNamed(IDR_STOP_P)); + go_->SetBackground(color, background, + tp->GetBitmapNamed(IDR_GO_MASK)); +} + +void ToolbarView::LoadRightSideControlsImages() { + ThemeProvider* tp = GetThemeProvider(); + + // We use different menu button images if the locale is right-to-left. + if (UILayoutIsRightToLeft()) + page_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_PAGE_RTL)); + else + page_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_PAGE)); + if (UILayoutIsRightToLeft()) + app_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_CHROME_RTL)); + else + app_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_CHROME)); +} + +void ToolbarView::RunPageMenu(const gfx::Point& pt, gfx::NativeView parent) { views::Menu::AnchorPoint anchor = views::Menu::TOPRIGHT; if (UILayoutIsRightToLeft()) anchor = views::Menu::TOPLEFT; @@ -693,8 +969,7 @@ void BrowserToolbarView::RunPageMenu(const gfx::Point& pt, menu->RunMenuAt(pt.x(), pt.y()); } -void BrowserToolbarView::RunAppMenu(const gfx::Point& pt, - gfx::NativeView parent) { +void ToolbarView::RunAppMenu(const gfx::Point& pt, gfx::NativeView parent) { views::Menu::AnchorPoint anchor = views::Menu::TOPRIGHT; if (UILayoutIsRightToLeft()) anchor = views::Menu::TOPLEFT; @@ -754,250 +1029,3 @@ void BrowserToolbarView::RunAppMenu(const gfx::Point& pt, // Menu is going away, so set the profiles menu pointer to NULL. profiles_menu_ = NULL; } - -bool BrowserToolbarView::IsItemChecked(int id) const { - if (!profile_) - return false; - if (id == IDC_SHOW_BOOKMARK_BAR) - return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); - return EncodingMenuControllerDelegate::IsItemChecked(id); -} - -void BrowserToolbarView::RunMenu(views::View* source, const gfx::Point& pt, - gfx::NativeView parent) { - switch (source->GetID()) { - case VIEW_ID_PAGE_MENU: - RunPageMenu(pt, parent); - break; - case VIEW_ID_APP_MENU: - RunAppMenu(pt, parent); - break; - default: - NOTREACHED() << "Invalid source menu."; - } -} - -void BrowserToolbarView::OnGetProfilesDone( - const std::vector<std::wstring>& profiles) { - // Nothing to do if the menu has gone away. - if (!profiles_menu_) - return; - - // Store the latest list of profiles in the browser. - browser_->set_user_data_dir_profiles(profiles); - - // Add direct sub menu items for profiles. - std::vector<std::wstring>::const_iterator iter = profiles.begin(); - for (int i = IDC_NEW_WINDOW_PROFILE_0; - (i <= IDC_NEW_WINDOW_PROFILE_LAST) && (iter != profiles.end()); - ++i, ++iter) - profiles_menu_->AppendMenuItemWithLabel(i, *iter); - - // If there are more profiles then show "Other" link. - if (iter != profiles.end()) { - profiles_menu_->AppendSeparator(); - profiles_menu_->AppendMenuItemWithLabel( - IDC_SELECT_PROFILE, l10n_util::GetString(IDS_SELECT_PROFILE)); - } - - // Always show a link to select a new profile. - profiles_menu_->AppendSeparator(); - profiles_menu_->AppendMenuItemWithLabel( - IDC_NEW_PROFILE, - l10n_util::GetString(IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY)); -} - -bool BrowserToolbarView::GetAccessibleName(std::wstring* name) { - if (!accessible_name_.empty()) { - (*name).assign(accessible_name_); - return true; - } - return false; -} - -bool BrowserToolbarView::GetAccessibleRole(AccessibilityTypes::Role* role) { - DCHECK(role); - - *role = AccessibilityTypes::ROLE_TOOLBAR; - return true; -} - -void BrowserToolbarView::SetAccessibleName(const std::wstring& name) { - accessible_name_.assign(name); -} - -void BrowserToolbarView::ThemeChanged() { - LoadLeftSideControlsImages(); - LoadCenterStackImages(); - LoadRightSideControlsImages(); -} - -int BrowserToolbarView::GetNextAccessibleViewIndex(int view_index, - bool nav_left) { - int modifier = 1; - - if (nav_left) - modifier = -1; - - int current_view_index = view_index + modifier; - - while ((current_view_index >= 0) && - (current_view_index < GetChildViewCount())) { - // Skip the location bar, as it has its own keyboard navigation. Also skip - // any views that cannot be interacted with. - if (current_view_index == GetChildIndex(location_bar_) || - !GetChildViewAt(current_view_index)->IsEnabled() || - !GetChildViewAt(current_view_index)->IsVisible()) { - current_view_index += modifier; - continue; - } - // Update view_index with the available button index found. - view_index = current_view_index; - break; - } - // Returns the next available button index, or if no button is available in - // the specified direction, remains where it was. - return view_index; -} - -void BrowserToolbarView::ShowContextMenu(int x, int y, bool is_mouse_gesture) { - if (acc_focused_view_) - acc_focused_view_->ShowContextMenu(x, y, is_mouse_gesture); -} - -int BrowserToolbarView::GetDragOperations(views::View* sender, int x, int y) { - DCHECK(sender == star_); - if (!tab_ || !tab_->ShouldDisplayURL() || !tab_->GetURL().is_valid()) { - return DragDropTypes::DRAG_NONE; - } - if (profile_ && profile_->GetBookmarkModel() && - profile_->GetBookmarkModel()->IsBookmarked(tab_->GetURL())) { - return DragDropTypes::DRAG_MOVE | DragDropTypes::DRAG_COPY | - DragDropTypes::DRAG_LINK; - } - return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK; -} - -void BrowserToolbarView::WriteDragData(views::View* sender, - int press_x, - int press_y, - OSExchangeData* data) { - DCHECK( - GetDragOperations(sender, press_x, press_y) != DragDropTypes::DRAG_NONE); - - UserMetrics::RecordAction(L"Toolbar_DragStar", profile_); - -#if defined(OS_WIN) - // If there is a bookmark for the URL, add the bookmark drag data for it. We - // do this to ensure the bookmark is moved, rather than creating an new - // bookmark. - if (profile_ && profile_->GetBookmarkModel()) { - BookmarkNode* node = profile_->GetBookmarkModel()-> - GetMostRecentlyAddedNodeForURL(tab_->GetURL()); - if (node) { - BookmarkDragData bookmark_data(node); - bookmark_data.Write(profile_, data); - } - } - - drag_utils::SetURLAndDragImage(tab_->GetURL(), - UTF16ToWideHack(tab_->GetTitle()), - tab_->GetFavIcon(), - data); -#else - // TODO(port): do bookmark item drag & drop - NOTIMPLEMENTED(); -#endif -} - -TabContents* BrowserToolbarView::GetTabContents() { - return tab_; -} - -void BrowserToolbarView::EnabledStateChangedForCommand(int id, bool enabled) { - views::Button* button = NULL; - switch (id) { - case IDC_BACK: - button = back_; - break; - case IDC_FORWARD: - button = forward_; - break; - case IDC_RELOAD: - button = reload_; - break; - case IDC_HOME: - button = home_; - break; - case IDC_STAR: - button = star_; - break; - } - if (button) - button->SetEnabled(enabled); -} - -void BrowserToolbarView::ButtonPressed(views::Button* sender) { - browser_->ExecuteCommandWithDisposition( - sender->tag(), - event_utils::DispositionFromEventFlags(sender->mouse_event_flags())); -} - -gfx::Rect BrowserToolbarView::GetPopupBounds() const { - gfx::Point origin; - views::View::ConvertPointToScreen(star_, &origin); - origin.set_y(origin.y() + star_->height() + kOmniboxPopupVerticalSpacing); - gfx::Rect popup_bounds(origin.x(), origin.y(), - star_->width() + location_bar_->width() + go_->width(), - 0); - if (UILayoutIsRightToLeft()) { - popup_bounds.set_x( - popup_bounds.x() - location_bar_->width() - go_->width()); - } else { - popup_bounds.set_x(popup_bounds.x()); - } - popup_bounds.set_y(popup_bounds.y()); - popup_bounds.set_width(popup_bounds.width()); - // Inset the bounds a little, since the buttons on either edge of the omnibox - // have invisible padding that makes the popup appear too wide. - popup_bounds.Inset(kOmniboxButtonsHorizontalMargin, 0); - return popup_bounds; -} - -// static -int BrowserToolbarView::PopupTopSpacing() { - return GetWindow()->GetNonClientView()->UseNativeFrame() ? - 0 : kPopupTopSpacingNonGlass; -} - -void BrowserToolbarView::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) { - std::wstring* pref_name = Details<std::wstring>(details).ptr(); - if (*pref_name == prefs::kShowHomeButton) { - Layout(); - SchedulePaint(); - } - } -} - -bool BrowserToolbarView::GetAcceleratorInfo(int id, - views::Accelerator* accel) { - // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators - // anywhere so we need to check for them explicitly here. - // TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings. - switch (id) { - case IDC_CUT: - *accel = views::Accelerator(L'X', false, true, false); - return true; - case IDC_COPY: - *accel = views::Accelerator(L'C', false, true, false); - return true; - case IDC_PASTE: - *accel = views::Accelerator(L'V', false, true, false); - return true; - } - // Else, we retrieve the accelerator information from the frame. - return GetWidget()->GetAccelerator(id, accel); -} diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index ba72763..e6fcdac 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -26,77 +26,34 @@ class Browser; class Profile; class ToolbarStarToggle; -/////////////////////////////////////////////////////////////////////////////// -// -// BrowserToolbarView class -// -// The BrowserToolbarView is responsible for constructing the content of and -// rendering the Toolbar used in the Browser Window -// -/////////////////////////////////////////////////////////////////////////////// -class BrowserToolbarView : public views::View, - public EncodingMenuControllerDelegate, - public views::ViewMenuDelegate, - public views::DragController, - public LocationBarView::Delegate, - public NotificationObserver, - public GetProfilesHelper::Delegate, - public CommandUpdater::CommandObserver, - public views::ButtonListener, - public AutocompletePopupPositioner { +// The Browser Window's toolbar. Used within BrowserView. +class ToolbarView : public views::View, + public EncodingMenuControllerDelegate, + public views::ViewMenuDelegate, + public views::DragController, + public LocationBarView::Delegate, + public NotificationObserver, + public GetProfilesHelper::Delegate, + public CommandUpdater::CommandObserver, + public views::ButtonListener, + public AutocompletePopupPositioner { public: - explicit BrowserToolbarView(Browser* browser); - virtual ~BrowserToolbarView(); + explicit ToolbarView(Browser* browser); + virtual ~ToolbarView(); // Create the contents of the Browser Toolbar void Init(Profile* profile); - // views::View - virtual void Layout(); - virtual void Paint(gfx::Canvas* canvas); - virtual void DidGainFocus(); - virtual void WillLoseFocus(); - virtual bool OnKeyPressed(const views::KeyEvent& e); - virtual bool OnKeyReleased(const views::KeyEvent& e); - virtual gfx::Size GetPreferredSize(); - virtual bool GetAccessibleName(std::wstring* name); - virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); - virtual void SetAccessibleName(const std::wstring& name); - virtual void ThemeChanged(); - - // Overridden from EncodingMenuControllerDelegate: - virtual bool IsItemChecked(int id) const; - - // Overridden from Menu::BaseControllerDelegate: - virtual bool GetAcceleratorInfo(int id, views::Accelerator* accel); - - // views::MenuDelegate - virtual void RunMenu(views::View* source, const gfx::Point& pt, - gfx::NativeView hwnd); - - // GetProfilesHelper::Delegate method. - virtual void OnGetProfilesDone(const std::vector<std::wstring>& profiles); - // Sets the profile which is active on the currently-active tab. void SetProfile(Profile* profile); Profile* profile() { return profile_; } - ToolbarStarToggle* star_button() { return star_; } - - GoButton* GetGoButton() { return go_; } - - LocationBarView* GetLocationBarView() const { return location_bar_; } - // Updates the toolbar (and transitively the location bar) with the states of // the specified |tab|. If |should_restore_state| is true, we're switching // (back?) to this tab and should restore any previous location bar state // (such as user editing) as well. void Update(TabContents* tab, bool should_restore_state); - virtual void OnInputInProgress(bool in_progress); - - virtual View* GetAccFocusedChildView() { return acc_focused_view_; } - // Returns the index of the next view of the toolbar, starting from the given // view index (skipping the location bar), in the given navigation direction // (nav_left true means navigation right to left, and vice versa). -1 finds @@ -107,10 +64,28 @@ class BrowserToolbarView : public views::View, acc_focused_view_ = acc_focused_view; } - // Returns the selected tab. - virtual TabContents* GetTabContents(); + // Accessors... + Browser* browser() const { return browser_; } + ToolbarStarToggle* star_button() const { return star_; } + GoButton* go_button() const { return go_; } + LocationBarView* location_bar() const { return location_bar_; } - Browser* browser() { return browser_; } + // Overridden from EncodingMenuControllerDelegate: + virtual bool IsItemChecked(int id) const; + + // Overridden from Menu::BaseControllerDelegate: + virtual bool GetAcceleratorInfo(int id, views::Accelerator* accel); + + // Overridden from views::MenuDelegate: + virtual void RunMenu(views::View* source, const gfx::Point& pt, + gfx::NativeView hwnd); + + // Overridden from GetProfilesHelper::Delegate: + virtual void OnGetProfilesDone(const std::vector<std::wstring>& profiles); + + // Overridden from LocationBarView::Delegate: + virtual TabContents* GetTabContents(); + virtual void OnInputInProgress(bool in_progress); // Overridden from CommandUpdater::CommandObserver: virtual void EnabledStateChangedForCommand(int id, bool enabled); @@ -121,21 +96,30 @@ class BrowserToolbarView : public views::View, // Overridden from AutocompletePopupPositioner: virtual gfx::Rect GetPopupBounds() const; - private: - // Types of display mode this toolbar can have. - enum DisplayMode { - DISPLAYMODE_NORMAL, - DISPLAYMODE_LOCATION - }; - - // Returns the number of pixels above the location bar in non-normal display. - int PopupTopSpacing(); - - // NotificationObserver + // Overridden from NotificationObserver: virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); + // Overridden from views::View: + virtual gfx::Size GetPreferredSize(); + virtual void Layout(); + virtual void Paint(gfx::Canvas* canvas); + virtual void ThemeChanged(); + virtual void ShowContextMenu(int x, int y, bool is_mouse_gesture); + virtual void DidGainFocus(); + virtual void WillLoseFocus(); + virtual bool OnKeyPressed(const views::KeyEvent& e); + virtual bool OnKeyReleased(const views::KeyEvent& e); + virtual bool GetAccessibleName(std::wstring* name); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual void SetAccessibleName(const std::wstring& name); + virtual View* GetAccFocusedChildView() { return acc_focused_view_; } + + private: + // Returns the number of pixels above the location bar in non-normal display. + int PopupTopSpacing() const; + // DragController methods for the star button. These allow the drag if the // user hasn't edited the text, the url is valid and should be displayed. virtual void WriteDragData(View* sender, @@ -152,21 +136,16 @@ class BrowserToolbarView : public views::View, void LoadCenterStackImages(); void LoadRightSideControlsImages(); - // Updates the controls to display the security appropriately (highlighted if - // secure). - void SetSecurityLevel(ToolbarModel::SecurityLevel security_level); - - // Show the page menu. + // Runs various menus. void RunPageMenu(const gfx::Point& pt, gfx::NativeView hwnd); - - // Show the app menu. void RunAppMenu(const gfx::Point& pt, gfx::NativeView hwnd); - // Overridden from View, to pass keyboard triggering of the right-click - // context menu on to the toolbar child view that currently has the - // accessibility focus. - virtual void ShowContextMenu(int x, int y, bool is_mouse_gesture); - + // Types of display mode this toolbar can have. + enum DisplayMode { + DISPLAYMODE_NORMAL, // Normal toolbar with buttons, etc. + DISPLAYMODE_LOCATION // Slimline toolbar showing only compact location + // bar, used for popups. + }; bool IsDisplayModeNormal() const { return display_mode_ == DISPLAYMODE_NORMAL; } |