| OLD | NEW |
| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/command_updater.h" | 16 #include "chrome/browser/command_updater.h" |
| 17 #include "chrome/browser/extensions/extension_util.h" | 17 #include "chrome/browser/extensions/extension_util.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/themes/theme_properties.h" | 19 #include "chrome/browser/themes/theme_properties.h" |
| 20 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_command_controller.h" | 22 #include "chrome/browser/ui/browser_command_controller.h" |
| 22 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
| 23 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" | 24 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
| 24 #include "chrome/browser/ui/browser_tabstrip.h" | 25 #include "chrome/browser/ui/browser_tabstrip.h" |
| 25 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
| 26 #include "chrome/browser/ui/global_error/global_error_service.h" | 27 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 27 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 28 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 28 #include "chrome/browser/ui/layout_constants.h" | 29 #include "chrome/browser/ui/layout_constants.h" |
| 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 30 #include "chrome/browser/ui/view_ids.h" | 31 #include "chrome/browser/ui/view_ids.h" |
| 31 #include "chrome/browser/ui/views/autofill/save_card_icon_view.h" | 32 #include "chrome/browser/ui/views/autofill/save_card_icon_view.h" |
| 33 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" |
| 32 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 34 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 33 #include "chrome/browser/ui/views/frame/browser_view.h" | 35 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 34 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 36 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 35 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 37 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 36 #include "chrome/browser/ui/views/location_bar/star_view.h" | 38 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 37 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" | 39 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" |
| 38 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 40 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 39 #include "chrome/browser/ui/views/toolbar/back_button.h" | 41 #include "chrome/browser/ui/views/toolbar/back_button.h" |
| 40 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 42 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 41 #include "chrome/browser/ui/views/toolbar/home_button.h" | 43 #include "chrome/browser/ui/views/toolbar/home_button.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 280 |
| 279 void ToolbarView::SetPaneFocusAndFocusAppMenu() { | 281 void ToolbarView::SetPaneFocusAndFocusAppMenu() { |
| 280 if (app_menu_button_) | 282 if (app_menu_button_) |
| 281 SetPaneFocus(app_menu_button_); | 283 SetPaneFocus(app_menu_button_); |
| 282 } | 284 } |
| 283 | 285 |
| 284 bool ToolbarView::IsAppMenuFocused() { | 286 bool ToolbarView::IsAppMenuFocused() { |
| 285 return app_menu_button_ && app_menu_button_->HasFocus(); | 287 return app_menu_button_ && app_menu_button_->HasFocus(); |
| 286 } | 288 } |
| 287 | 289 |
| 288 views::View* ToolbarView::GetBookmarkBubbleAnchor() { | 290 void ToolbarView::ShowBookmarkBubble( |
| 289 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) | 291 const GURL& url, |
| 290 return location_bar(); | 292 bool already_bookmarked, |
| 293 bookmarks::BookmarkBubbleObserver* observer) { |
| 294 views::View* anchor_view = location_bar(); |
| 295 StarView* star_view = location_bar()->star_view(); |
| 296 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 297 if (star_view && star_view->visible()) |
| 298 anchor_view = star_view; |
| 299 else |
| 300 anchor_view = app_menu_button_; |
| 301 } |
| 291 | 302 |
| 292 views::View* star_view = location_bar()->star_view(); | 303 std::unique_ptr<BubbleSyncPromoDelegate> delegate; |
| 293 return (star_view && star_view->visible()) ? star_view : app_menu_button_; | 304 delegate.reset(new BookmarkBubbleSignInDelegate(browser_)); |
| 305 views::Widget* bubble_widget = BookmarkBubbleView::ShowBubble( |
| 306 anchor_view, gfx::Rect(), nullptr, observer, std::move(delegate), |
| 307 browser_->profile(), url, already_bookmarked); |
| 308 if (star_view) |
| 309 bubble_widget->AddObserver(star_view); |
| 294 } | 310 } |
| 295 | 311 |
| 296 views::View* ToolbarView::GetSaveCreditCardBubbleAnchor() { | 312 views::View* ToolbarView::GetSaveCreditCardBubbleAnchor() { |
| 297 views::View* save_credit_card_icon_view = | 313 views::View* save_credit_card_icon_view = |
| 298 location_bar()->save_credit_card_icon_view(); | 314 location_bar()->save_credit_card_icon_view(); |
| 299 return (save_credit_card_icon_view && save_credit_card_icon_view->visible()) | 315 return (save_credit_card_icon_view && save_credit_card_icon_view->visible()) |
| 300 ? save_credit_card_icon_view | 316 ? save_credit_card_icon_view |
| 301 : app_menu_button_; | 317 : app_menu_button_; |
| 302 } | 318 } |
| 303 | 319 |
| 304 views::View* ToolbarView::GetTranslateBubbleAnchor() { | 320 views::View* ToolbarView::GetTranslateBubbleAnchor() { |
| 305 views::View* translate_icon_view = location_bar()->translate_icon_view(); | 321 views::View* translate_icon_view = location_bar()->translate_icon_view(); |
| 306 return (translate_icon_view && translate_icon_view->visible()) | 322 return (translate_icon_view && translate_icon_view->visible()) |
| 307 ? translate_icon_view | 323 ? translate_icon_view |
| 308 : app_menu_button_; | 324 : app_menu_button_; |
| 309 } | 325 } |
| 310 | 326 |
| 311 void ToolbarView::OnBubbleCreatedForAnchor(views::View* anchor_view, | 327 void ToolbarView::OnBubbleCreatedForAnchor(views::View* anchor_view, |
| 312 views::Widget* bubble_widget) { | 328 views::Widget* bubble_widget) { |
| 313 if (bubble_widget && | 329 if (bubble_widget && |
| 314 (anchor_view == location_bar()->star_view() || | 330 (anchor_view == location_bar()->save_credit_card_icon_view() || |
| 315 anchor_view == location_bar()->save_credit_card_icon_view() || | |
| 316 anchor_view == location_bar()->translate_icon_view())) { | 331 anchor_view == location_bar()->translate_icon_view())) { |
| 317 DCHECK(anchor_view); | 332 DCHECK(anchor_view); |
| 318 bubble_widget->AddObserver(static_cast<BubbleIconView*>(anchor_view)); | 333 bubble_widget->AddObserver(static_cast<BubbleIconView*>(anchor_view)); |
| 319 } | 334 } |
| 320 } | 335 } |
| 321 | 336 |
| 322 int ToolbarView::GetMaxBrowserActionsWidth() const { | 337 int ToolbarView::GetMaxBrowserActionsWidth() const { |
| 323 // The browser actions container is allowed to grow, but only up until the | 338 // The browser actions container is allowed to grow, but only up until the |
| 324 // omnibox reaches its minimum size. So its maximum allowed width is its | 339 // omnibox reaches its minimum size. So its maximum allowed width is its |
| 325 // current size, plus any that the omnibox could give up. | 340 // current size, plus any that the omnibox could give up. |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 if (OutdatedUpgradeBubbleView::IsAvailable()) { | 757 if (OutdatedUpgradeBubbleView::IsAvailable()) { |
| 743 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, | 758 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, |
| 744 auto_update_enabled); | 759 auto_update_enabled); |
| 745 } | 760 } |
| 746 } | 761 } |
| 747 | 762 |
| 748 void ToolbarView::OnShowHomeButtonChanged() { | 763 void ToolbarView::OnShowHomeButtonChanged() { |
| 749 Layout(); | 764 Layout(); |
| 750 SchedulePaint(); | 765 SchedulePaint(); |
| 751 } | 766 } |
| OLD | NEW |