Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/ui/views/toolbar_view.cc

Issue 10630013: Adds LocationBarContainer that contains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove set_view_to_focus Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/toolbar_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/toolbar_view.h" 5 #include "chrome/browser/ui/views/toolbar_view.h"
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/event_disposition.h" 10 #include "chrome/browser/event_disposition.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" 14 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
15 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/global_error_service.h" 16 #include "chrome/browser/ui/global_error_service.h"
17 #include "chrome/browser/ui/global_error_service_factory.h" 17 #include "chrome/browser/ui/global_error_service_factory.h"
18 #include "chrome/browser/ui/omnibox/omnibox_view.h" 18 #include "chrome/browser/ui/omnibox/omnibox_view.h"
19 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" 19 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
20 #include "chrome/browser/ui/view_ids.h" 20 #include "chrome/browser/ui/view_ids.h"
21 #include "chrome/browser/ui/views/browser_actions_container.h" 21 #include "chrome/browser/ui/views/browser_actions_container.h"
22 #include "chrome/browser/ui/views/location_bar/location_bar_container.h"
22 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 23 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
23 #include "chrome/browser/ui/views/wrench_menu.h" 24 #include "chrome/browser/ui/views/wrench_menu.h"
24 #include "chrome/browser/upgrade_detector.h" 25 #include "chrome/browser/upgrade_detector.h"
25 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "content/public/browser/browser_accessibility_state.h" 28 #include "content/public/browser/browser_accessibility_state.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/user_metrics.h" 30 #include "content/public/browser/user_metrics.h"
30 #include "grit/chromium_strings.h" 31 #include "grit/chromium_strings.h"
31 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 //////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////
117 // ToolbarView, public: 118 // ToolbarView, public:
118 119
119 ToolbarView::ToolbarView(Browser* browser) 120 ToolbarView::ToolbarView(Browser* browser)
120 : model_(browser->toolbar_model()), 121 : model_(browser->toolbar_model()),
121 back_(NULL), 122 back_(NULL),
122 forward_(NULL), 123 forward_(NULL),
123 reload_(NULL), 124 reload_(NULL),
124 home_(NULL), 125 home_(NULL),
125 location_bar_(NULL), 126 location_bar_(NULL),
127 location_bar_container_(NULL),
126 browser_actions_(NULL), 128 browser_actions_(NULL),
127 app_menu_(NULL), 129 app_menu_(NULL),
128 browser_(browser), 130 browser_(browser),
129 profiles_menu_contents_(NULL) { 131 profiles_menu_contents_(NULL) {
130 set_id(VIEW_ID_TOOLBAR); 132 set_id(VIEW_ID_TOOLBAR);
131 133
132 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); 134 browser_->command_updater()->AddCommandObserver(IDC_BACK, this);
133 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); 135 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this);
134 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); 136 browser_->command_updater()->AddCommandObserver(IDC_HOME, this);
135 137
(...skipping 17 matching lines...) Expand all
153 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, 155 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
154 content::Source<Profile>(browser_->profile())); 156 content::Source<Profile>(browser_->profile()));
155 } 157 }
156 158
157 ToolbarView::~ToolbarView() { 159 ToolbarView::~ToolbarView() {
158 // NOTE: Don't remove the command observers here. This object gets destroyed 160 // NOTE: Don't remove the command observers here. This object gets destroyed
159 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is 161 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is
160 // already gone. 162 // already gone.
161 } 163 }
162 164
163 void ToolbarView::Init(views::View* popup_parent_view) { 165 void ToolbarView::Init(views::View* location_bar_parent,
166 views::View* popup_parent_view) {
164 back_menu_model_.reset(new BackForwardMenuModel( 167 back_menu_model_.reset(new BackForwardMenuModel(
165 browser_, BackForwardMenuModel::BACKWARD_MENU)); 168 browser_, BackForwardMenuModel::BACKWARD_MENU));
166 forward_menu_model_.reset(new BackForwardMenuModel( 169 forward_menu_model_.reset(new BackForwardMenuModel(
167 browser_, BackForwardMenuModel::FORWARD_MENU)); 170 browser_, BackForwardMenuModel::FORWARD_MENU));
168 back_ = new views::ButtonDropDown(this, back_menu_model_.get()); 171 back_ = new views::ButtonDropDown(this, back_menu_model_.get());
169 back_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | 172 back_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON |
170 ui::EF_MIDDLE_MOUSE_BUTTON); 173 ui::EF_MIDDLE_MOUSE_BUTTON);
171 back_->set_tag(IDC_BACK); 174 back_->set_tag(IDC_BACK);
172 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, 175 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT,
173 views::ImageButton::ALIGN_TOP); 176 views::ImageButton::ALIGN_TOP);
174 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)); 177 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK));
175 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); 178 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK));
176 back_->set_id(VIEW_ID_BACK_BUTTON); 179 back_->set_id(VIEW_ID_BACK_BUTTON);
177 180
178 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get()); 181 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get());
179 forward_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | 182 forward_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON |
180 ui::EF_MIDDLE_MOUSE_BUTTON); 183 ui::EF_MIDDLE_MOUSE_BUTTON);
181 forward_->set_tag(IDC_FORWARD); 184 forward_->set_tag(IDC_FORWARD);
182 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); 185 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD));
183 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); 186 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD));
184 forward_->set_id(VIEW_ID_FORWARD_BUTTON); 187 forward_->set_id(VIEW_ID_FORWARD_BUTTON);
185 188
186 // Have to create this before |reload_| as |reload_|'s constructor needs it. 189 // Have to create this before |reload_| as |reload_|'s constructor needs it.
190 location_bar_container_ = new LocationBarContainer(location_bar_parent);
187 location_bar_ = new LocationBarView( 191 location_bar_ = new LocationBarView(
188 browser_->profile(), 192 browser_->profile(),
189 browser_->command_updater(), 193 browser_->command_updater(),
190 model_, 194 model_,
191 this, 195 this,
192 (display_mode_ == DISPLAYMODE_LOCATION) ? 196 (display_mode_ == DISPLAYMODE_LOCATION) ?
193 LocationBarView::POPUP : LocationBarView::NORMAL); 197 LocationBarView::POPUP : LocationBarView::NORMAL);
198 // TODO(sky): if we want this to work on windows we need to make sure the
199 // LocationBarContainer gets focus. This will involve tweaking view_ids.
200 // location_bar_->set_view_to_focus(location_bar_container_);
201 location_bar_container_->SetLocationBarView(location_bar_);
194 202
195 reload_ = new ReloadButton(location_bar_, browser_->command_updater()); 203 reload_ = new ReloadButton(location_bar_, browser_->command_updater());
196 reload_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | 204 reload_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON |
197 ui::EF_MIDDLE_MOUSE_BUTTON); 205 ui::EF_MIDDLE_MOUSE_BUTTON);
198 reload_->set_tag(IDC_RELOAD); 206 reload_->set_tag(IDC_RELOAD);
199 reload_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_RELOAD)); 207 reload_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_RELOAD));
200 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); 208 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD));
201 reload_->set_id(VIEW_ID_RELOAD_BUTTON); 209 reload_->set_id(VIEW_ID_RELOAD_BUTTON);
202 210
203 home_ = new views::ImageButton(this); 211 home_ = new views::ImageButton(this);
(...skipping 23 matching lines...) Expand all
227 if (ShouldShowUpgradeRecommended() || ShouldShowIncompatibilityWarning()) { 235 if (ShouldShowUpgradeRecommended() || ShouldShowIncompatibilityWarning()) {
228 UpdateAppMenuState(); 236 UpdateAppMenuState();
229 } 237 }
230 LoadImages(); 238 LoadImages();
231 239
232 // Always add children in order from left to right, for accessibility. 240 // Always add children in order from left to right, for accessibility.
233 AddChildView(back_); 241 AddChildView(back_);
234 AddChildView(forward_); 242 AddChildView(forward_);
235 AddChildView(reload_); 243 AddChildView(reload_);
236 AddChildView(home_); 244 AddChildView(home_);
237 AddChildView(location_bar_);
238 AddChildView(browser_actions_); 245 AddChildView(browser_actions_);
239 AddChildView(app_menu_); 246 AddChildView(app_menu_);
240 247
241 location_bar_->Init(popup_parent_view); 248 location_bar_->Init(popup_parent_view);
242 show_home_button_.Init(prefs::kShowHomeButton, 249 show_home_button_.Init(prefs::kShowHomeButton,
243 browser_->profile()->GetPrefs(), this); 250 browser_->profile()->GetPrefs(), this);
244 browser_actions_->Init(); 251 browser_actions_->Init();
245 252
246 // Accessibility specific tooltip text. 253 // Accessibility specific tooltip text.
247 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { 254 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) {
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // ToolbarView, views::View overrides: 539 // ToolbarView, views::View overrides:
533 540
534 gfx::Size ToolbarView::GetPreferredSize() { 541 gfx::Size ToolbarView::GetPreferredSize() {
535 if (IsDisplayModeNormal()) { 542 if (IsDisplayModeNormal()) {
536 int min_width = kLeftEdgeSpacing + 543 int min_width = kLeftEdgeSpacing +
537 back_->GetPreferredSize().width() + kButtonSpacing + 544 back_->GetPreferredSize().width() + kButtonSpacing +
538 forward_->GetPreferredSize().width() + kButtonSpacing + 545 forward_->GetPreferredSize().width() + kButtonSpacing +
539 reload_->GetPreferredSize().width() + kStandardSpacing + 546 reload_->GetPreferredSize().width() + kStandardSpacing +
540 (show_home_button_.GetValue() ? 547 (show_home_button_.GetValue() ?
541 (home_->GetPreferredSize().width() + kButtonSpacing) : 0) + 548 (home_->GetPreferredSize().width() + kButtonSpacing) : 0) +
542 location_bar_->GetPreferredSize().width() + 549 location_bar_container_->GetPreferredSize().width() +
543 browser_actions_->GetPreferredSize().width() + 550 browser_actions_->GetPreferredSize().width() +
544 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; 551 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing;
545 552
546 CR_DEFINE_STATIC_LOCAL(gfx::ImageSkia, normal_background, ()); 553 CR_DEFINE_STATIC_LOCAL(gfx::ImageSkia, normal_background, ());
547 if (normal_background.isNull()) { 554 if (normal_background.isNull()) {
548 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 555 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
549 normal_background = *rb.GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); 556 normal_background = *rb.GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
550 } 557 }
551 558
552 return gfx::Size(min_width, 559 return gfx::Size(min_width,
553 normal_background.height() - kContentShadowHeight); 560 normal_background.height() - kContentShadowHeight);
554 } 561 }
555 562
556 int vertical_spacing = PopupTopSpacing() + 563 int vertical_spacing = PopupTopSpacing() +
557 (GetWidget()->ShouldUseNativeFrame() ? 564 (GetWidget()->ShouldUseNativeFrame() ?
558 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); 565 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass);
559 return gfx::Size(0, location_bar_->GetPreferredSize().height() + 566 return gfx::Size(0, location_bar_container_->GetPreferredSize().height() +
560 vertical_spacing); 567 vertical_spacing);
561 } 568 }
562 569
563 void ToolbarView::Layout() { 570 void ToolbarView::Layout() {
564 // If we have not been initialized yet just do nothing. 571 // If we have not been initialized yet just do nothing.
565 if (back_ == NULL) 572 if (back_ == NULL)
566 return; 573 return;
567 574
568 bool maximized = browser_->window() && browser_->window()->IsMaximized(); 575 bool maximized = browser_->window() && browser_->window()->IsMaximized();
569 if (!IsDisplayModeNormal()) { 576 if (!IsDisplayModeNormal()) {
570 int edge_width = maximized ? 577 int edge_width = maximized ?
571 0 : kPopupBackgroundEdge->width(); // See OnPaint(). 578 0 : kPopupBackgroundEdge->width(); // See OnPaint().
572 location_bar_->SetBounds(edge_width, PopupTopSpacing(), 579 SetLocationBarContainerBounds(gfx::Rect(edge_width, PopupTopSpacing(),
573 width() - (edge_width * 2), location_bar_->GetPreferredSize().height()); 580 std::max(0, width() - (edge_width * 2)),
581 location_bar_container_->GetPreferredSize().height()));
574 return; 582 return;
575 } 583 }
576 584
577 int child_y = std::min(kVertSpacing, height()); 585 int child_y = std::min(kVertSpacing, height());
578 // We assume all child elements are the same height. 586 // We assume all child elements are the same height.
579 int child_height = 587 int child_height =
580 std::min(back_->GetPreferredSize().height(), height() - child_y); 588 std::min(back_->GetPreferredSize().height(), height() - child_y);
581 589
582 // If the window is maximized, we extend the back button to the left so that 590 // If the window is maximized, we extend the back button to the left so that
583 // clicking on the left-most pixel will activate the back button. 591 // clicking on the left-most pixel will activate the back button.
(...skipping 22 matching lines...) Expand all
606 home_->SetVisible(false); 614 home_->SetVisible(false);
607 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); 615 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height);
608 } 616 }
609 617
610 int browser_actions_width = browser_actions_->GetPreferredSize().width(); 618 int browser_actions_width = browser_actions_->GetPreferredSize().width();
611 int app_menu_width = app_menu_->GetPreferredSize().width(); 619 int app_menu_width = app_menu_->GetPreferredSize().width();
612 int location_x = home_->x() + home_->width() + kStandardSpacing; 620 int location_x = home_->x() + home_->width() + kStandardSpacing;
613 int available_width = width() - kRightEdgeSpacing - app_menu_width - 621 int available_width = width() - kRightEdgeSpacing - app_menu_width -
614 browser_actions_width - location_x; 622 browser_actions_width - location_x;
615 int location_y = std::min(location_bar_vert_spacing(), height()); 623 int location_y = std::min(location_bar_vert_spacing(), height());
616 int location_bar_height = location_bar_->GetPreferredSize().height(); 624 int location_bar_height =
625 location_bar_container_->GetPreferredSize().height();
617 626
618 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), 627 gfx::Rect location_bar_container_bounds(
619 location_bar_height); 628 location_x, location_y, std::max(available_width, 0),
629 location_bar_height);
630 SetLocationBarContainerBounds(location_bar_container_bounds);
620 631
621 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, 632 browser_actions_->SetBounds(location_bar_container_bounds.right(), 0,
622 browser_actions_width, height()); 633 browser_actions_width, height());
623 // The browser actions need to do a layout explicitly, because when an 634 // The browser actions need to do a layout explicitly, because when an
624 // extension is loaded/unloaded/changed, BrowserActionContainer removes and 635 // extension is loaded/unloaded/changed, BrowserActionContainer removes and
625 // re-adds everything, regardless of whether it has a page action. For a 636 // re-adds everything, regardless of whether it has a page action. For a
626 // page action, browser action bounds do not change, as a result of which 637 // page action, browser action bounds do not change, as a result of which
627 // SetBounds does not do a layout at all. 638 // SetBounds does not do a layout at all.
628 // TODO(sidchat): Rework the above behavior so that explicit layout is not 639 // TODO(sidchat): Rework the above behavior so that explicit layout is not
629 // required. 640 // required.
630 browser_actions_->Layout(); 641 browser_actions_->Layout();
631 642
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 accname_app = l10n_util::GetStringFUTF16( 831 accname_app = l10n_util::GetStringFUTF16(
821 IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app); 832 IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app);
822 } 833 }
823 app_menu_->SetAccessibleName(accname_app); 834 app_menu_->SetAccessibleName(accname_app);
824 835
825 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL)); 836 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL));
826 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); 837 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT));
827 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); 838 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED));
828 SchedulePaint(); 839 SchedulePaint();
829 } 840 }
841
842 void ToolbarView::SetLocationBarContainerBounds(
843 const gfx::Rect& bounds) {
844 if (location_bar_container_->IsAnimating())
845 return;
846
847 // LocationBarContainer is not a child of the ToolbarView.
848 gfx::Point origin(bounds.origin());
849 views::View::ConvertPointToView(this, location_bar_container_->parent(),
850 &origin);
851 gfx::Rect target_bounds(origin, bounds.size());
852 if (location_bar_container_->GetTargetBounds() != target_bounds)
853 location_bar_container_->SetBoundsRect(target_bounds);
854 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698