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

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: Created 7 years, 1 month 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/frame/browser_view.h" 31 #include "chrome/browser/ui/views/frame/browser_view.h"
31 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 32 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
32 #include "chrome/browser/ui/views/location_bar/star_view.h" 33 #include "chrome/browser/ui/views/location_bar/star_view.h"
33 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" 34 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
34 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" 35 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
35 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 36 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
36 #include "chrome/browser/ui/views/toolbar/button_dropdown.h" 37 #include "chrome/browser/ui/views/toolbar/button_dropdown.h"
37 #include "chrome/browser/ui/views/toolbar/home_button.h" 38 #include "chrome/browser/ui/views/toolbar/home_button.h"
38 #include "chrome/browser/ui/views/toolbar/reload_button.h" 39 #include "chrome/browser/ui/views/toolbar/reload_button.h"
40 #include "chrome/browser/ui/views/toolbar/site_chip_view.h"
39 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" 41 #include "chrome/browser/ui/views/toolbar/wrench_menu.h"
40 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" 42 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
41 #include "chrome/browser/upgrade_detector.h" 43 #include "chrome/browser/upgrade_detector.h"
42 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
43 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
44 #include "content/public/browser/browser_accessibility_state.h" 46 #include "content/public/browser/browser_accessibility_state.h"
45 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/render_view_host.h" 48 #include "content/public/browser/render_view_host.h"
47 #include "content/public/browser/user_metrics.h" 49 #include "content/public/browser/user_metrics.h"
48 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 114
113 //////////////////////////////////////////////////////////////////////////////// 115 ////////////////////////////////////////////////////////////////////////////////
114 // ToolbarView, public: 116 // ToolbarView, public:
115 117
116 ToolbarView::ToolbarView(Browser* browser) 118 ToolbarView::ToolbarView(Browser* browser)
117 : back_(NULL), 119 : back_(NULL),
118 forward_(NULL), 120 forward_(NULL),
119 reload_(NULL), 121 reload_(NULL),
120 home_(NULL), 122 home_(NULL),
121 location_bar_(NULL), 123 location_bar_(NULL),
124 site_chip_view_(NULL),
122 browser_actions_(NULL), 125 browser_actions_(NULL),
123 app_menu_(NULL), 126 app_menu_(NULL),
124 browser_(browser) { 127 browser_(browser) {
125 set_id(VIEW_ID_TOOLBAR); 128 set_id(VIEW_ID_TOOLBAR);
126 129
127 chrome::AddCommandObserver(browser_, IDC_BACK, this); 130 chrome::AddCommandObserver(browser_, IDC_BACK, this);
128 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); 131 chrome::AddCommandObserver(browser_, IDC_FORWARD, this);
129 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); 132 chrome::AddCommandObserver(browser_, IDC_RELOAD, this);
130 chrome::AddCommandObserver(browser_, IDC_HOME, this); 133 chrome::AddCommandObserver(browser_, IDC_HOME, this);
131 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); 134 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); 219 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP));
217 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); 220 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP));
218 app_menu_->set_id(VIEW_ID_APP_MENU); 221 app_menu_->set_id(VIEW_ID_APP_MENU);
219 222
220 // Always add children in order from left to right, for accessibility. 223 // Always add children in order from left to right, for accessibility.
221 AddChildView(back_); 224 AddChildView(back_);
222 AddChildView(forward_); 225 AddChildView(forward_);
223 AddChildView(reload_); 226 AddChildView(reload_);
224 AddChildView(home_); 227 AddChildView(home_);
225 AddChildView(location_bar_); 228 AddChildView(location_bar_);
229 if (chrome::ShouldDisplayOriginChip()) {
230 // use --force-fieldtrials=EmbeddedSearch/Group1 origin_chip:1/ to force
Peter Kasting 2013/11/19 02:47:32 Nit: I would prefer not to document this here.
Greg Billock 2013/11/20 01:27:35 Done.
231 site_chip_view_ = new SiteChipView(this);
Peter Kasting 2013/11/19 02:47:32 Nit: Instead of conditionally creating this, consi
Greg Billock 2013/11/20 01:28:48 Good point. Will do that in another patch.
232 AddChildView(site_chip_view_);
233 }
226 AddChildView(browser_actions_); 234 AddChildView(browser_actions_);
227 AddChildView(app_menu_); 235 AddChildView(app_menu_);
228 236
229 LoadImages(); 237 LoadImages();
230 238
231 // Add any necessary badges to the menu item based on the system state. 239 // Add any necessary badges to the menu item based on the system state.
232 // Do this after |app_menu_| has been added as a bubble may be shown that 240 // Do this after |app_menu_| has been added as a bubble may be shown that
233 // needs the widget (widget found by way of app_menu_->GetWidget()). 241 // needs the widget (widget found by way of app_menu_->GetWidget()).
234 UpdateAppMenuState(); 242 UpdateAppMenuState();
235 243
236 location_bar_->Init(); 244 location_bar_->Init();
245 if (site_chip_view_)
246 site_chip_view_->Init();
237 show_home_button_.Init(prefs::kShowHomeButton, 247 show_home_button_.Init(prefs::kShowHomeButton,
238 browser_->profile()->GetPrefs(), 248 browser_->profile()->GetPrefs(),
239 base::Bind(&ToolbarView::OnShowHomeButtonChanged, 249 base::Bind(&ToolbarView::OnShowHomeButtonChanged,
240 base::Unretained(this))); 250 base::Unretained(this)));
241 251
242 browser_actions_->Init(); 252 browser_actions_->Init();
243 253
244 // Accessibility specific tooltip text. 254 // Accessibility specific tooltip text.
245 if (content::BrowserAccessibilityState::GetInstance()-> 255 if (content::BrowserAccessibilityState::GetInstance()->
246 IsAccessibleBrowser()) { 256 IsAccessibleBrowser()) {
247 back_->SetTooltipText( 257 back_->SetTooltipText(
248 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); 258 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK));
249 forward_->SetTooltipText( 259 forward_->SetTooltipText(
250 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); 260 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD));
251 } 261 }
252 } 262 }
253 263
254 void ToolbarView::Update(WebContents* tab) { 264 void ToolbarView::Update(WebContents* tab) {
255 if (location_bar_) 265 if (location_bar_)
256 location_bar_->Update(tab); 266 location_bar_->Update(tab);
267 if (site_chip_view_)
268 site_chip_view_->Update(tab);
257 269
258 if (browser_actions_) 270 if (browser_actions_)
259 browser_actions_->RefreshBrowserActionViews(); 271 browser_actions_->RefreshBrowserActionViews();
260 272
261 if (reload_) 273 if (reload_)
262 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); 274 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_));
263 } 275 }
264 276
265 void ToolbarView::SetPaneFocusAndFocusAppMenu() { 277 void ToolbarView::SetPaneFocusAndFocusAppMenu() {
266 SetPaneFocus(app_menu_); 278 SetPaneFocus(app_menu_);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 gfx::Size ToolbarView::GetPreferredSize() { 480 gfx::Size ToolbarView::GetPreferredSize() {
469 if (is_display_mode_normal()) { 481 if (is_display_mode_normal()) {
470 int button_spacing = GetButtonSpacing(); 482 int button_spacing = GetButtonSpacing();
471 int min_width = kLeftEdgeSpacing + 483 int min_width = kLeftEdgeSpacing +
472 back_->GetPreferredSize().width() + button_spacing + 484 back_->GetPreferredSize().width() + button_spacing +
473 forward_->GetPreferredSize().width() + button_spacing + 485 forward_->GetPreferredSize().width() + button_spacing +
474 reload_->GetPreferredSize().width() + kStandardSpacing + 486 reload_->GetPreferredSize().width() + kStandardSpacing +
475 (show_home_button_.GetValue() ? 487 (show_home_button_.GetValue() ?
476 (home_->GetPreferredSize().width() + button_spacing) : 0) + 488 (home_->GetPreferredSize().width() + button_spacing) : 0) +
477 location_bar_->GetPreferredSize().width() + 489 location_bar_->GetPreferredSize().width() +
490 (site_chip_view_ ? site_chip_view_->GetPreferredSize().width() : 0) +
478 browser_actions_->GetPreferredSize().width() + 491 browser_actions_->GetPreferredSize().width() +
479 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; 492 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing;
480 gfx::ImageSkia* normal_background = 493 gfx::ImageSkia* normal_background =
481 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); 494 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
482 return gfx::Size(min_width, 495 return gfx::Size(min_width,
483 normal_background->height() - content_shadow_height()); 496 normal_background->height() - content_shadow_height());
484 } 497 }
485 498
486 const int kPopupBottomSpacingGlass = 1; 499 const int kPopupBottomSpacingGlass = 1;
487 const int kPopupBottomSpacingNonGlass = 2; 500 const int kPopupBottomSpacingNonGlass = 2;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if (show_home_button_.GetValue()) { 547 if (show_home_button_.GetValue()) {
535 home_->SetVisible(true); 548 home_->SetVisible(true);
536 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, 549 home_->SetBounds(reload_->x() + reload_->width() + button_spacing,
537 child_y, home_->GetPreferredSize().width(), child_height); 550 child_y, home_->GetPreferredSize().width(), child_height);
538 } else { 551 } else {
539 home_->SetVisible(false); 552 home_->SetVisible(false);
540 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); 553 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height);
541 } 554 }
542 555
543 int browser_actions_width = browser_actions_->GetPreferredSize().width(); 556 int browser_actions_width = browser_actions_->GetPreferredSize().width();
557 int site_chip_width =
558 site_chip_view_ ? site_chip_view_->GetPreferredSize().width() : 0;
544 int app_menu_width = app_menu_->GetPreferredSize().width(); 559 int app_menu_width = app_menu_->GetPreferredSize().width();
545 int location_x = home_->x() + home_->width() + kStandardSpacing; 560 int location_x = home_->x() + home_->width() + kStandardSpacing;
546 int available_width = std::max(0, width() - kRightEdgeSpacing - 561 int available_width = std::max(0, width() - kRightEdgeSpacing -
547 app_menu_width - browser_actions_width - location_x); 562 app_menu_width - browser_actions_width - location_x);
548 563
564 // Cap site chip width at 1/2 the size available to the location bar.
565 site_chip_width = std::min(site_chip_width, available_width/2);
Peter Kasting 2013/11/19 02:47:32 Nit: Spaces around operators Be careful in your s
Greg Billock 2013/11/20 01:27:35 Yeah, that's a regression -- it will currently shr
566 available_width -= site_chip_width;
567
549 int location_height = location_bar_->GetPreferredSize().height(); 568 int location_height = location_bar_->GetPreferredSize().height();
550 int location_y = (height() - location_height + 1) / 2; 569 int location_y = (height() - location_height + 1) / 2;
551 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), 570 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0),
552 location_height); 571 location_height);
553 572
554 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, 573 int browser_actions_x = location_bar_->x() + location_bar_->width();
574 if (site_chip_view_) {
575 site_chip_view_->SetBounds(location_bar_->x() + location_bar_->width(),
576 child_y, site_chip_width, child_height);
577 browser_actions_x += site_chip_width;
578 }
579 browser_actions_->SetBounds(browser_actions_x, 0,
555 browser_actions_width, height()); 580 browser_actions_width, height());
581
556 // The browser actions need to do a layout explicitly, because when an 582 // The browser actions need to do a layout explicitly, because when an
557 // extension is loaded/unloaded/changed, BrowserActionContainer removes and 583 // extension is loaded/unloaded/changed, BrowserActionContainer removes and
558 // re-adds everything, regardless of whether it has a page action. For a 584 // re-adds everything, regardless of whether it has a page action. For a
559 // page action, browser action bounds do not change, as a result of which 585 // page action, browser action bounds do not change, as a result of which
560 // SetBounds does not do a layout at all. 586 // SetBounds does not do a layout at all.
561 // TODO(sidchat): Rework the above behavior so that explicit layout is not 587 // TODO(sidchat): Rework the above behavior so that explicit layout is not
562 // required. 588 // required.
563 browser_actions_->Layout(); 589 browser_actions_->Layout();
564 590
565 // Extend the app menu to the screen's right edge in maximized mode just like 591 // 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
788 814
789 void ToolbarView::OnShowHomeButtonChanged() { 815 void ToolbarView::OnShowHomeButtonChanged() {
790 Layout(); 816 Layout();
791 SchedulePaint(); 817 SchedulePaint();
792 } 818 }
793 819
794 int ToolbarView::content_shadow_height() const { 820 int ToolbarView::content_shadow_height() const {
795 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? 821 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ?
796 kContentShadowHeightAsh : kContentShadowHeight; 822 kContentShadowHeightAsh : kContentShadowHeight;
797 } 823 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698