Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/location_bar/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.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/command_updater.h" | 15 #include "chrome/browser/command_updater.h" |
| 16 #include "chrome/browser/defaults.h" | 16 #include "chrome/browser/defaults.h" |
| 17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 18 #include "chrome/browser/extensions/extension_action.h" | 18 #include "chrome/browser/extensions/extension_action.h" |
| 19 #include "chrome/browser/extensions/extension_action_manager.h" | 19 #include "chrome/browser/extensions/extension_action_manager.h" |
| 20 #include "chrome/browser/extensions/extension_util.h" | 20 #include "chrome/browser/extensions/extension_util.h" |
| 21 #include "chrome/browser/extensions/location_bar_controller.h" | 21 #include "chrome/browser/extensions/location_bar_controller.h" |
| 22 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/search_engines/template_url_service_factory.h" | 24 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 25 #include "chrome/browser/themes/theme_properties.h" | 25 #include "chrome/browser/themes/theme_properties.h" |
| 26 #include "chrome/browser/themes/theme_service.h" | |
| 26 #include "chrome/browser/translate/chrome_translate_client.h" | 27 #include "chrome/browser/translate/chrome_translate_client.h" |
| 27 #include "chrome/browser/translate/translate_service.h" | 28 #include "chrome/browser/translate/translate_service.h" |
| 28 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" | 29 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
| 29 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/browser/ui/browser_finder.h" | 31 #include "chrome/browser/ui/browser_finder.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 32 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 33 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 33 #include "chrome/browser/ui/layout_constants.h" | 34 #include "chrome/browser/ui/layout_constants.h" |
| 34 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 35 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 #include "ui/views/controls/label.h" | 96 #include "ui/views/controls/label.h" |
| 96 #include "ui/views/widget/widget.h" | 97 #include "ui/views/widget/widget.h" |
| 97 | 98 |
| 98 #if !defined(OS_CHROMEOS) | 99 #if !defined(OS_CHROMEOS) |
| 99 #include "chrome/browser/ui/views/first_run_bubble.h" | 100 #include "chrome/browser/ui/views/first_run_bubble.h" |
| 100 #endif | 101 #endif |
| 101 | 102 |
| 102 using content::WebContents; | 103 using content::WebContents; |
| 103 using views::View; | 104 using views::View; |
| 104 | 105 |
| 105 namespace { | |
| 106 | |
| 107 // The border color, drawn on top of the toolbar. | |
| 108 const SkColor kBorderColor = SkColorSetA(SK_ColorBLACK, 0x4D); | |
| 109 | |
| 110 } // namespace | |
| 111 | |
| 112 | 106 |
| 113 // LocationBarView ----------------------------------------------------------- | 107 // LocationBarView ----------------------------------------------------------- |
| 114 | 108 |
| 115 // static | 109 // static |
| 116 const char LocationBarView::kViewClassName[] = "LocationBarView"; | 110 const char LocationBarView::kViewClassName[] = "LocationBarView"; |
| 117 | 111 |
| 118 LocationBarView::LocationBarView(Browser* browser, | 112 LocationBarView::LocationBarView(Browser* browser, |
| 119 Profile* profile, | 113 Profile* profile, |
| 120 CommandUpdater* command_updater, | 114 CommandUpdater* command_updater, |
| 121 Delegate* delegate, | 115 Delegate* delegate, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 152 if (template_url_service_) | 146 if (template_url_service_) |
| 153 template_url_service_->RemoveObserver(this); | 147 template_url_service_->RemoveObserver(this); |
| 154 | 148 |
| 155 zoom::ZoomEventManager::GetForBrowserContext(profile()) | 149 zoom::ZoomEventManager::GetForBrowserContext(profile()) |
| 156 ->RemoveZoomEventManagerObserver(this); | 150 ->RemoveZoomEventManagerObserver(this); |
| 157 } | 151 } |
| 158 | 152 |
| 159 //////////////////////////////////////////////////////////////////////////////// | 153 //////////////////////////////////////////////////////////////////////////////// |
| 160 // LocationBarView, public: | 154 // LocationBarView, public: |
| 161 | 155 |
| 162 // static | |
| 163 SkColor LocationBarView::GetOpaqueBorderColor(bool incognito) { | |
| 164 return color_utils::GetResultingPaintColor( | |
| 165 kBorderColor, ThemeProperties::GetDefaultColor( | |
| 166 ThemeProperties::COLOR_TOOLBAR, incognito)); | |
| 167 } | |
| 168 | |
| 169 void LocationBarView::Init() { | 156 void LocationBarView::Init() { |
| 170 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're | 157 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're |
| 171 // not prepared for that. | 158 // not prepared for that. |
| 172 DCHECK(GetWidget()); | 159 DCHECK(GetWidget()); |
| 173 | 160 |
| 174 // Make sure children with layers are clipped. See http://crbug.com/589497 | 161 // Make sure children with layers are clipped. See http://crbug.com/589497 |
| 175 SetPaintToLayer(); | 162 SetPaintToLayer(); |
| 176 layer()->SetFillsBoundsOpaquely(false); | 163 layer()->SetFillsBoundsOpaquely(false); |
| 177 layer()->SetMasksToBounds(true); | 164 layer()->SetMasksToBounds(true); |
| 178 | 165 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 case DEEMPHASIZED_TEXT: | 284 case DEEMPHASIZED_TEXT: |
| 298 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); | 285 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); |
| 299 | 286 |
| 300 case SECURITY_CHIP_TEXT: | 287 case SECURITY_CHIP_TEXT: |
| 301 return GetSecureTextColor(GetToolbarModel()->GetSecurityLevel(false)); | 288 return GetSecureTextColor(GetToolbarModel()->GetSecurityLevel(false)); |
| 302 } | 289 } |
| 303 NOTREACHED(); | 290 NOTREACHED(); |
| 304 return gfx::kPlaceholderColor; | 291 return gfx::kPlaceholderColor; |
| 305 } | 292 } |
| 306 | 293 |
| 294 SkColor LocationBarView::GetOpaqueBorderColor(bool incognito) { | |
|
Peter Kasting
2017/02/11 10:18:46
Should be const
| |
| 295 return color_utils::GetResultingPaintColor( | |
| 296 GetBorderColor(), ThemeProperties::GetDefaultColor( | |
| 297 ThemeProperties::COLOR_TOOLBAR, incognito)); | |
| 298 } | |
| 299 | |
| 307 SkColor LocationBarView::GetSecureTextColor( | 300 SkColor LocationBarView::GetSecureTextColor( |
| 308 security_state::SecurityLevel security_level) const { | 301 security_state::SecurityLevel security_level) const { |
| 309 if (security_level == security_state::SECURE_WITH_POLICY_INSTALLED_CERT) { | 302 if (security_level == security_state::SECURE_WITH_POLICY_INSTALLED_CERT) { |
| 310 return GetColor(DEEMPHASIZED_TEXT); | 303 return GetColor(DEEMPHASIZED_TEXT); |
| 311 } | 304 } |
| 312 | 305 |
| 313 SkColor text_color = GetColor(TEXT); | 306 SkColor text_color = GetColor(TEXT); |
| 314 if (!color_utils::IsDark(GetColor(BACKGROUND))) { | 307 if (!color_utils::IsDark(GetColor(BACKGROUND))) { |
| 315 if ((security_level == security_state::EV_SECURE) || | 308 if ((security_level == security_state::EV_SECURE) || |
| 316 (security_level == security_state::SECURE)) { | 309 (security_level == security_state::SECURE)) { |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 | 600 |
| 608 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 601 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 609 RefreshLocationIcon(); | 602 RefreshLocationIcon(); |
| 610 if (is_popup_mode_) { | 603 if (is_popup_mode_) { |
| 611 set_background( | 604 set_background( |
| 612 views::Background::CreateSolidBackground(GetColor(BACKGROUND))); | 605 views::Background::CreateSolidBackground(GetColor(BACKGROUND))); |
| 613 } else { | 606 } else { |
| 614 // This border color will be blended on top of the toolbar (which may use an | 607 // This border color will be blended on top of the toolbar (which may use an |
| 615 // image in the case of themes). | 608 // image in the case of themes). |
| 616 set_background( | 609 set_background( |
| 617 new BackgroundWith1PxBorder(GetColor(BACKGROUND), kBorderColor)); | 610 new BackgroundWith1PxBorder(GetColor(BACKGROUND), GetBorderColor())); |
| 618 } | 611 } |
| 619 SchedulePaint(); | 612 SchedulePaint(); |
| 620 } | 613 } |
| 621 | 614 |
| 622 void LocationBarView::Update(const WebContents* contents) { | 615 void LocationBarView::Update(const WebContents* contents) { |
| 623 RefreshContentSettingViews(); | 616 RefreshContentSettingViews(); |
| 624 RefreshZoomView(); | 617 RefreshZoomView(); |
| 625 RefreshPageActionViews(); | 618 RefreshPageActionViews(); |
| 626 RefreshTranslateIcon(); | 619 RefreshTranslateIcon(); |
| 627 RefreshSaveCreditCardIconView(); | 620 RefreshSaveCreditCardIconView(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 | 655 |
| 663 //////////////////////////////////////////////////////////////////////////////// | 656 //////////////////////////////////////////////////////////////////////////////// |
| 664 // LocationBarView, private: | 657 // LocationBarView, private: |
| 665 | 658 |
| 666 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { | 659 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { |
| 667 return view->visible() ? (GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) + | 660 return view->visible() ? (GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) + |
| 668 view->GetMinimumSize().width()) | 661 view->GetMinimumSize().width()) |
| 669 : 0; | 662 : 0; |
| 670 } | 663 } |
| 671 | 664 |
| 665 SkColor LocationBarView::GetBorderColor() { | |
|
Peter Kasting
2017/02/11 10:18:46
Should be const
| |
| 666 return GetThemeProvider()->GetColor( | |
| 667 ThemeProperties::COLOR_LOCATION_BAR_BORDER); | |
| 668 } | |
| 669 | |
| 672 int LocationBarView::GetHorizontalEdgeThickness() const { | 670 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 673 return is_popup_mode_ | 671 return is_popup_mode_ |
| 674 ? 0 | 672 ? 0 |
| 675 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip; | 673 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip; |
| 676 } | 674 } |
| 677 | 675 |
| 678 int LocationBarView::GetTotalVerticalPadding() const { | 676 int LocationBarView::GetTotalVerticalPadding() const { |
| 679 return BackgroundWith1PxBorder::kLocationBarBorderThicknessDip + | 677 return BackgroundWith1PxBorder::kLocationBarBorderThicknessDip + |
| 680 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); | 678 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); |
| 681 } | 679 } |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1190 // LocationBarView, private TemplateURLServiceObserver implementation: | 1188 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1191 | 1189 |
| 1192 void LocationBarView::OnTemplateURLServiceChanged() { | 1190 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1193 template_url_service_->RemoveObserver(this); | 1191 template_url_service_->RemoveObserver(this); |
| 1194 template_url_service_ = nullptr; | 1192 template_url_service_ = nullptr; |
| 1195 // If the browser is no longer active, let's not show the info bubble, as this | 1193 // If the browser is no longer active, let's not show the info bubble, as this |
| 1196 // would make the browser the active window again. | 1194 // would make the browser the active window again. |
| 1197 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1195 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1198 ShowFirstRunBubble(); | 1196 ShowFirstRunBubble(); |
| 1199 } | 1197 } |
| OLD | NEW |