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

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

Issue 75873002: [SiteChip] Add the basic painting of the site chip button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use constants Created 7 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/toolbar_view.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/i18n/number_formatting.h" 9 #include "base/i18n/number_formatting.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/command_updater.h" 14 #include "chrome/browser/command_updater.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search/search.h"
16 #include "chrome/browser/themes/theme_service.h" 17 #include "chrome/browser/themes/theme_service.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_command_controller.h" 19 #include "chrome/browser/ui/browser_command_controller.h"
19 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" 21 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
21 #include "chrome/browser/ui/browser_instant_controller.h" 22 #include "chrome/browser/ui/browser_instant_controller.h"
22 #include "chrome/browser/ui/browser_tabstrip.h" 23 #include "chrome/browser/ui/browser_tabstrip.h"
23 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/global_error/global_error_service.h" 25 #include "chrome/browser/ui/global_error/global_error_service.h"
25 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 26 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
26 #include "chrome/browser/ui/omnibox/omnibox_view.h" 27 #include "chrome/browser/ui/omnibox/omnibox_view.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" 29 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
29 #include "chrome/browser/ui/view_ids.h" 30 #include "chrome/browser/ui/view_ids.h"
30 #include "chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h" 31 #include "chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h"
31 #include "chrome/browser/ui/views/frame/browser_view.h" 32 #include "chrome/browser/ui/views/frame/browser_view.h"
32 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 33 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
33 #include "chrome/browser/ui/views/location_bar/star_view.h" 34 #include "chrome/browser/ui/views/location_bar/star_view.h"
34 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" 35 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
35 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" 36 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
36 #include "chrome/browser/ui/views/toolbar/back_button.h" 37 #include "chrome/browser/ui/views/toolbar/back_button.h"
37 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 38 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
38 #include "chrome/browser/ui/views/toolbar/home_button.h" 39 #include "chrome/browser/ui/views/toolbar/home_button.h"
39 #include "chrome/browser/ui/views/toolbar/reload_button.h" 40 #include "chrome/browser/ui/views/toolbar/reload_button.h"
41 #include "chrome/browser/ui/views/toolbar/site_chip_view.h"
40 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" 42 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
41 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" 43 #include "chrome/browser/ui/views/toolbar/wrench_menu.h"
42 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" 44 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
43 #include "chrome/browser/upgrade_detector.h" 45 #include "chrome/browser/upgrade_detector.h"
44 #include "chrome/common/chrome_switches.h" 46 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/pref_names.h" 47 #include "chrome/common/pref_names.h"
46 #include "content/public/browser/browser_accessibility_state.h" 48 #include "content/public/browser/browser_accessibility_state.h"
47 #include "content/public/browser/notification_service.h" 49 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/render_view_host.h" 50 #include "content/public/browser/render_view_host.h"
49 #include "content/public/browser/user_metrics.h" 51 #include "content/public/browser/user_metrics.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 116
115 //////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////
116 // ToolbarView, public: 118 // ToolbarView, public:
117 119
118 ToolbarView::ToolbarView(Browser* browser) 120 ToolbarView::ToolbarView(Browser* browser)
119 : back_(NULL), 121 : back_(NULL),
120 forward_(NULL), 122 forward_(NULL),
121 reload_(NULL), 123 reload_(NULL),
122 home_(NULL), 124 home_(NULL),
123 location_bar_(NULL), 125 location_bar_(NULL),
126 site_chip_view_(NULL),
124 browser_actions_(NULL), 127 browser_actions_(NULL),
125 app_menu_(NULL), 128 app_menu_(NULL),
126 browser_(browser) { 129 browser_(browser) {
127 set_id(VIEW_ID_TOOLBAR); 130 set_id(VIEW_ID_TOOLBAR);
128 131
129 chrome::AddCommandObserver(browser_, IDC_BACK, this); 132 chrome::AddCommandObserver(browser_, IDC_BACK, this);
130 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); 133 chrome::AddCommandObserver(browser_, IDC_FORWARD, this);
131 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); 134 chrome::AddCommandObserver(browser_, IDC_RELOAD, this);
132 chrome::AddCommandObserver(browser_, IDC_HOME, this); 135 chrome::AddCommandObserver(browser_, IDC_HOME, this);
133 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); 136 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); 223 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP));
221 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); 224 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP));
222 app_menu_->set_id(VIEW_ID_APP_MENU); 225 app_menu_->set_id(VIEW_ID_APP_MENU);
223 226
224 // Always add children in order from left to right, for accessibility. 227 // Always add children in order from left to right, for accessibility.
225 AddChildView(back_); 228 AddChildView(back_);
226 AddChildView(forward_); 229 AddChildView(forward_);
227 AddChildView(reload_); 230 AddChildView(reload_);
228 AddChildView(home_); 231 AddChildView(home_);
229 AddChildView(location_bar_); 232 AddChildView(location_bar_);
233 site_chip_view_ = new SiteChipView(this);
234 AddChildView(site_chip_view_);
230 AddChildView(browser_actions_); 235 AddChildView(browser_actions_);
231 AddChildView(app_menu_); 236 AddChildView(app_menu_);
232 237
233 LoadImages(); 238 LoadImages();
234 239
235 // Add any necessary badges to the menu item based on the system state. 240 // Add any necessary badges to the menu item based on the system state.
236 // Do this after |app_menu_| has been added as a bubble may be shown that 241 // Do this after |app_menu_| has been added as a bubble may be shown that
237 // needs the widget (widget found by way of app_menu_->GetWidget()). 242 // needs the widget (widget found by way of app_menu_->GetWidget()).
238 UpdateAppMenuState(); 243 UpdateAppMenuState();
239 244
240 location_bar_->Init(); 245 location_bar_->Init();
246 site_chip_view_->Init();
241 show_home_button_.Init(prefs::kShowHomeButton, 247 show_home_button_.Init(prefs::kShowHomeButton,
242 browser_->profile()->GetPrefs(), 248 browser_->profile()->GetPrefs(),
243 base::Bind(&ToolbarView::OnShowHomeButtonChanged, 249 base::Bind(&ToolbarView::OnShowHomeButtonChanged,
244 base::Unretained(this))); 250 base::Unretained(this)));
245 251
246 browser_actions_->Init(); 252 browser_actions_->Init();
247 253
248 // Accessibility specific tooltip text. 254 // Accessibility specific tooltip text.
249 if (content::BrowserAccessibilityState::GetInstance()-> 255 if (content::BrowserAccessibilityState::GetInstance()->
250 IsAccessibleBrowser()) { 256 IsAccessibleBrowser()) {
251 back_->SetTooltipText( 257 back_->SetTooltipText(
252 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); 258 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK));
253 forward_->SetTooltipText( 259 forward_->SetTooltipText(
254 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); 260 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD));
255 } 261 }
256 } 262 }
257 263
258 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, 264 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget,
259 bool visible) { 265 bool visible) {
260 if (visible) { 266 if (visible) {
261 extensions::SuspiciousExtensionBubbleView::MaybeShow(browser_, app_menu_); 267 extensions::SuspiciousExtensionBubbleView::MaybeShow(browser_, app_menu_);
262 GetWidget()->RemoveObserver(this); 268 GetWidget()->RemoveObserver(this);
263 } 269 }
264 } 270 }
265 271
266 void ToolbarView::Update(WebContents* tab) { 272 void ToolbarView::Update(WebContents* tab) {
267 if (location_bar_) 273 if (location_bar_)
268 location_bar_->Update(tab); 274 location_bar_->Update(tab);
275 if (site_chip_view_)
276 site_chip_view_->Update(tab);
269 277
270 if (browser_actions_) 278 if (browser_actions_)
271 browser_actions_->RefreshBrowserActionViews(); 279 browser_actions_->RefreshBrowserActionViews();
272 280
273 if (reload_) 281 if (reload_)
274 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); 282 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_));
275 } 283 }
276 284
277 void ToolbarView::SetPaneFocusAndFocusAppMenu() { 285 void ToolbarView::SetPaneFocusAndFocusAppMenu() {
278 SetPaneFocus(app_menu_); 286 SetPaneFocus(app_menu_);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 ui::Accelerator* accelerator) { 481 ui::Accelerator* accelerator) {
474 return GetWidget()->GetAccelerator(command_id, accelerator); 482 return GetWidget()->GetAccelerator(command_id, accelerator);
475 } 483 }
476 484
477 //////////////////////////////////////////////////////////////////////////////// 485 ////////////////////////////////////////////////////////////////////////////////
478 // ToolbarView, views::View overrides: 486 // ToolbarView, views::View overrides:
479 487
480 gfx::Size ToolbarView::GetPreferredSize() { 488 gfx::Size ToolbarView::GetPreferredSize() {
481 if (is_display_mode_normal()) { 489 if (is_display_mode_normal()) {
482 int button_spacing = GetButtonSpacing(); 490 int button_spacing = GetButtonSpacing();
491 int site_chip_spacing = kStandardSpacing - 1;
Peter Kasting 2013/12/03 00:58:10 Nit: Don't calculate this value in two different p
Greg Billock 2013/12/03 17:35:08 This is just an artifact of how the images are pro
483 int min_width = kLeftEdgeSpacing + 492 int min_width = kLeftEdgeSpacing +
484 back_->GetPreferredSize().width() + button_spacing + 493 back_->GetPreferredSize().width() + button_spacing +
485 forward_->GetPreferredSize().width() + button_spacing + 494 forward_->GetPreferredSize().width() + button_spacing +
486 reload_->GetPreferredSize().width() + kStandardSpacing + 495 reload_->GetPreferredSize().width() + kStandardSpacing +
487 (show_home_button_.GetValue() ? 496 (show_home_button_.GetValue() ?
488 (home_->GetPreferredSize().width() + button_spacing) : 0) + 497 (home_->GetPreferredSize().width() + button_spacing) : 0) +
489 location_bar_->GetPreferredSize().width() + 498 location_bar_->GetPreferredSize().width() +
499 (site_chip_view_->ShouldShow() ?
500 site_chip_view_->GetPreferredSize().width() +
501 2*site_chip_spacing + 2*button_spacing : 0) +
Peter Kasting 2013/12/03 00:58:10 Nit: Spaces around operators Indent this line 4 m
Greg Billock 2013/12/03 17:35:08 Done.
490 browser_actions_->GetPreferredSize().width() + 502 browser_actions_->GetPreferredSize().width() +
491 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; 503 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing;
492 gfx::ImageSkia* normal_background = 504 gfx::ImageSkia* normal_background =
493 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); 505 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
494 return gfx::Size(min_width, 506 return gfx::Size(min_width,
495 normal_background->height() - content_shadow_height()); 507 normal_background->height() - content_shadow_height());
496 } 508 }
497 509
498 const int kPopupBottomSpacingGlass = 1; 510 const int kPopupBottomSpacingGlass = 1;
499 const int kPopupBottomSpacingNonGlass = 2; 511 const int kPopupBottomSpacingNonGlass = 2;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 if (show_home_button_.GetValue()) { 561 if (show_home_button_.GetValue()) {
550 home_->SetVisible(true); 562 home_->SetVisible(true);
551 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, 563 home_->SetBounds(reload_->x() + reload_->width() + button_spacing,
552 child_y, home_->GetPreferredSize().width(), child_height); 564 child_y, home_->GetPreferredSize().width(), child_height);
553 } else { 565 } else {
554 home_->SetVisible(false); 566 home_->SetVisible(false);
555 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); 567 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height);
556 } 568 }
557 569
558 int browser_actions_width = browser_actions_->GetPreferredSize().width(); 570 int browser_actions_width = browser_actions_->GetPreferredSize().width();
571
572 // Note: spacing from location bar to site chip is 1 pixel less than
573 // kStandardSpacing given the edge thickness of the chip.
574 int site_chip_spacing = kStandardSpacing - 1;
575 int site_chip_width =
576 (site_chip_view_->ShouldShow() ?
577 site_chip_view_->GetPreferredSize().width() +
578 2 * site_chip_spacing : 0);
559 int app_menu_width = app_menu_->GetPreferredSize().width(); 579 int app_menu_width = app_menu_->GetPreferredSize().width();
560 int location_x = home_->x() + home_->width() + kStandardSpacing; 580 int location_x = home_->x() + home_->width() + kStandardSpacing;
561 int available_width = std::max(0, width() - kRightEdgeSpacing - 581 int available_width = std::max(0, width() - kRightEdgeSpacing -
562 app_menu_width - browser_actions_width - location_x); 582 app_menu_width - browser_actions_width - location_x);
563 583
584 // Cap site chip width at 1/2 the size available to the location bar.
585 site_chip_width = std::min(site_chip_width, available_width / 2);
586 available_width -= site_chip_width;
587
564 int location_height = location_bar_->GetPreferredSize().height(); 588 int location_height = location_bar_->GetPreferredSize().height();
565 int location_y = (height() - location_height + 1) / 2; 589 int location_y = (height() - location_height + 1) / 2;
566 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), 590 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0),
567 location_height); 591 location_height);
568 592
569 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, 593 int browser_actions_x = location_bar_->x() + location_bar_->width();
Peter Kasting 2013/12/03 00:58:10 So we put the browser actions flush against the lo
Greg Billock 2013/12/03 17:35:08 The browser actions are borderless, so this is giv
594
595 if (site_chip_view_->ShouldShow()) {
596 site_chip_view_->SetBounds(location_bar_->x() + location_bar_->width() +
Peter Kasting 2013/12/03 00:58:10 Nit: Replace first two terms with "browser_actions
Greg Billock 2013/12/03 17:35:08 Done.
597 site_chip_spacing,
598 child_y,
599 site_chip_view_->GetPreferredSize().width(),
600 child_height);
601 browser_actions_x += site_chip_view_->GetPreferredSize().width() +
Peter Kasting 2013/12/03 00:58:10 Nit: Break after "+=" instead to avoid wrapping th
Greg Billock 2013/12/03 17:35:08 Done.
602 site_chip_spacing;
603 }
604
605 browser_actions_->SetBounds(browser_actions_x, 0,
570 browser_actions_width, height()); 606 browser_actions_width, height());
607
571 // The browser actions need to do a layout explicitly, because when an 608 // The browser actions need to do a layout explicitly, because when an
572 // extension is loaded/unloaded/changed, BrowserActionContainer removes and 609 // extension is loaded/unloaded/changed, BrowserActionContainer removes and
573 // re-adds everything, regardless of whether it has a page action. For a 610 // re-adds everything, regardless of whether it has a page action. For a
574 // page action, browser action bounds do not change, as a result of which 611 // page action, browser action bounds do not change, as a result of which
575 // SetBounds does not do a layout at all. 612 // SetBounds does not do a layout at all.
576 // TODO(sidchat): Rework the above behavior so that explicit layout is not 613 // TODO(sidchat): Rework the above behavior so that explicit layout is not
577 // required. 614 // required.
578 browser_actions_->Layout(); 615 browser_actions_->Layout();
579 616
580 // Extend the app menu to the screen's right edge in maximized mode just like 617 // Extend the app menu to the screen's right edge in maximized mode just like
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 840
804 void ToolbarView::OnShowHomeButtonChanged() { 841 void ToolbarView::OnShowHomeButtonChanged() {
805 Layout(); 842 Layout();
806 SchedulePaint(); 843 SchedulePaint();
807 } 844 }
808 845
809 int ToolbarView::content_shadow_height() const { 846 int ToolbarView::content_shadow_height() const {
810 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? 847 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ?
811 kContentShadowHeightAsh : kContentShadowHeight; 848 kContentShadowHeightAsh : kContentShadowHeight;
812 } 849 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698