| 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_icon_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ssl/chrome_security_state_model_client.h" | 8 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| 9 #include "chrome/browser/ui/view_ids.h" | 9 #include "chrome/browser/ui/view_ids.h" |
| 10 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 10 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 11 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h
" | 11 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h
" |
| 12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 13 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
| 14 #include "content/public/browser/navigation_entry.h" | 14 #include "content/public/browser/navigation_entry.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "grit/components_scaled_resources.h" | 16 #include "grit/components_scaled_resources.h" |
| 17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/material_design/material_design_controller.h" | 19 #include "ui/base/material_design/material_design_controller.h" |
| 20 #include "ui/gfx/color_palette.h" | 20 #include "ui/gfx/color_palette.h" |
| 21 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
| 22 #include "ui/views/painter.h" | 22 #include "ui/views/painter.h" |
| 23 | 23 |
| 24 using content::NavigationController; | 24 using content::NavigationController; |
| 25 using content::NavigationEntry; | 25 using content::NavigationEntry; |
| 26 using content::WebContents; | 26 using content::WebContents; |
| 27 | 27 |
| 28 namespace { | |
| 29 | |
| 30 void ProcessEventInternal(LocationBarView* view) { | |
| 31 WebContents* contents = view->GetWebContents(); | |
| 32 if (!contents) | |
| 33 return; | |
| 34 | |
| 35 // Important to use GetVisibleEntry to match what's showing in the omnibox. | |
| 36 NavigationEntry* entry = contents->GetController().GetVisibleEntry(); | |
| 37 // The visible entry can be nullptr in the case of window.open(""). | |
| 38 if (!entry) | |
| 39 return; | |
| 40 | |
| 41 ChromeSecurityStateModelClient* model_client = | |
| 42 ChromeSecurityStateModelClient::FromWebContents(contents); | |
| 43 DCHECK(model_client); | |
| 44 | |
| 45 view->delegate()->ShowWebsiteSettings(contents, entry->GetURL(), | |
| 46 model_client->GetSecurityInfo()); | |
| 47 } | |
| 48 | |
| 49 } // namespace | |
| 50 | |
| 51 LocationIconView::LocationIconView(const gfx::FontList& font_list, | 28 LocationIconView::LocationIconView(const gfx::FontList& font_list, |
| 52 SkColor parent_background_color, | 29 SkColor parent_background_color, |
| 53 LocationBarView* location_bar) | 30 LocationBarView* location_bar) |
| 54 : IconLabelBubbleView(IDR_OMNIBOX_HTTPS_INVALID, | 31 : IconLabelBubbleView(IDR_OMNIBOX_HTTPS_INVALID, |
| 55 font_list, | 32 font_list, |
| 56 parent_background_color, | 33 parent_background_color, |
| 57 true), | 34 true), |
| 58 suppress_mouse_released_action_(false), | 35 suppress_mouse_released_action_(false), |
| 59 location_bar_(location_bar) { | 36 location_bar_(location_bar) { |
| 60 set_id(VIEW_ID_LOCATION_ICON); | 37 set_id(VIEW_ID_LOCATION_ICON); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 75 |
| 99 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { | 76 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { |
| 100 location_bar_->GetOmniboxView()->CloseOmniboxPopup(); | 77 location_bar_->GetOmniboxView()->CloseOmniboxPopup(); |
| 101 return false; | 78 return false; |
| 102 } | 79 } |
| 103 | 80 |
| 104 bool LocationIconView::OnKeyPressed(const ui::KeyEvent& event) { | 81 bool LocationIconView::OnKeyPressed(const ui::KeyEvent& event) { |
| 105 return false; | 82 return false; |
| 106 } | 83 } |
| 107 | 84 |
| 108 bool LocationIconView::OnKeyReleased(const ui::KeyEvent& event) { | |
| 109 if (event.key_code() != ui::VKEY_RETURN && event.key_code() != ui::VKEY_SPACE) | |
| 110 return false; | |
| 111 ProcessEvent(event); | |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 void LocationIconView::OnGestureEvent(ui::GestureEvent* event) { | 85 void LocationIconView::OnGestureEvent(ui::GestureEvent* event) { |
| 116 if (event->type() != ui::ET_GESTURE_TAP) | 86 if (event->type() != ui::ET_GESTURE_TAP) |
| 117 return; | 87 return; |
| 118 OnClickOrTap(*event); | 88 OnClickOrTap(*event); |
| 119 event->SetHandled(); | 89 event->SetHandled(); |
| 120 } | 90 } |
| 121 | 91 |
| 122 bool LocationIconView::GetTooltipText(const gfx::Point& p, | 92 bool LocationIconView::GetTooltipText(const gfx::Point& p, |
| 123 base::string16* tooltip) const { | 93 base::string16* tooltip) const { |
| 124 if (show_tooltip_) | 94 if (show_tooltip_) |
| 125 *tooltip = l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON); | 95 *tooltip = l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON); |
| 126 return show_tooltip_; | 96 return show_tooltip_; |
| 127 } | 97 } |
| 128 | 98 |
| 129 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { | 99 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { |
| 130 // Do not show page info if the user has been editing the location bar or the | 100 // Do not show page info if the user has been editing the location bar or the |
| 131 // location bar is at the NTP. | 101 // location bar is at the NTP. |
| 132 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty()) | 102 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty()) |
| 133 return; | 103 return; |
| 134 ProcessEvent(event); | 104 ProcessLocatedEvent(event); |
| 135 } | 105 } |
| 136 | 106 |
| 137 void LocationIconView::ProcessEvent(const ui::LocatedEvent& event) { | 107 void LocationIconView::ProcessLocatedEvent(const ui::LocatedEvent& event) { |
| 138 if (!HitTestPoint(event.location())) | 108 if (HitTestPoint(event.location())) |
| 139 return; | 109 OnActivate(); |
| 140 ProcessEventInternal(location_bar_); | |
| 141 } | |
| 142 | |
| 143 void LocationIconView::ProcessEvent(const ui::KeyEvent& event) { | |
| 144 ProcessEventInternal(location_bar_); | |
| 145 } | 110 } |
| 146 | 111 |
| 147 gfx::Size LocationIconView::GetMinimumSize() const { | 112 gfx::Size LocationIconView::GetMinimumSize() const { |
| 148 return GetMinimumSizeForPreferredSize(GetPreferredSize()); | 113 return GetMinimumSizeForPreferredSize(GetPreferredSize()); |
| 149 } | 114 } |
| 150 | 115 |
| 151 gfx::Size LocationIconView::GetMinimumSizeForLabelText( | 116 gfx::Size LocationIconView::GetMinimumSizeForLabelText( |
| 152 const base::string16& text) const { | 117 const base::string16& text) const { |
| 153 views::Label label(text, font_list()); | 118 views::Label label(text, font_list()); |
| 154 return GetMinimumSizeForPreferredSize( | 119 return GetMinimumSizeForPreferredSize( |
| 155 GetSizeForLabelWidth(label.GetPreferredSize().width())); | 120 GetSizeForLabelWidth(label.GetPreferredSize().width())); |
| 156 } | 121 } |
| 157 | 122 |
| 158 SkColor LocationIconView::GetTextColor() const { | 123 SkColor LocationIconView::GetTextColor() const { |
| 159 return location_bar_->GetColor(LocationBarView::EV_BUBBLE_TEXT_AND_BORDER); | 124 return location_bar_->GetColor(LocationBarView::EV_BUBBLE_TEXT_AND_BORDER); |
| 160 } | 125 } |
| 161 | 126 |
| 162 SkColor LocationIconView::GetBorderColor() const { | 127 SkColor LocationIconView::GetBorderColor() const { |
| 163 return GetTextColor(); | 128 return GetTextColor(); |
| 164 } | 129 } |
| 165 | 130 |
| 131 bool LocationIconView::OnActivate() { |
| 132 WebContents* contents = location_bar_->GetWebContents(); |
| 133 if (!contents) |
| 134 return false; |
| 135 |
| 136 // Important to use GetVisibleEntry to match what's showing in the omnibox. |
| 137 NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
| 138 // The visible entry can be nullptr in the case of window.open(""). |
| 139 if (!entry) |
| 140 return false; |
| 141 |
| 142 ChromeSecurityStateModelClient* model_client = |
| 143 ChromeSecurityStateModelClient::FromWebContents(contents); |
| 144 DCHECK(model_client); |
| 145 |
| 146 location_bar_->delegate()->ShowWebsiteSettings( |
| 147 contents, entry->GetURL(), model_client->GetSecurityInfo()); |
| 148 return true; |
| 149 } |
| 150 |
| 166 gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( | 151 gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( |
| 167 gfx::Size size) const { | 152 gfx::Size size) const { |
| 168 const int kMinCharacters = 10; | 153 const int kMinCharacters = 10; |
| 169 size.SetToMin( | 154 size.SetToMin( |
| 170 GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters))); | 155 GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters))); |
| 171 return size; | 156 return size; |
| 172 } | 157 } |
| 173 | 158 |
| 174 void LocationIconView::SetBackground(bool should_show_ev) { | 159 void LocationIconView::SetBackground(bool should_show_ev) { |
| 175 static const int kEvBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_EV_BUBBLE); | 160 static const int kEvBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_EV_BUBBLE); |
| 176 if (should_show_ev) | 161 if (should_show_ev) |
| 177 SetBackgroundImageGrid(kEvBackgroundImages); | 162 SetBackgroundImageGrid(kEvBackgroundImages); |
| 178 else | 163 else |
| 179 UnsetBackgroundImageGrid(); | 164 UnsetBackgroundImageGrid(); |
| 180 } | 165 } |
| OLD | NEW |