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 "components/omnibox/browser/omnibox_edit_model.h" | 13 #include "components/omnibox/browser/omnibox_edit_model.h" |
14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "grit/components_scaled_resources.h" | 17 #include "grit/components_scaled_resources.h" |
18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/material_design/material_design_controller.h" | 20 #include "ui/base/material_design/material_design_controller.h" |
21 #include "ui/gfx/color_palette.h" | 21 #include "ui/gfx/color_palette.h" |
22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
23 #include "ui/views/painter.h" | 23 #include "ui/views/painter.h" |
24 | 24 |
25 using content::NavigationController; | |
26 using content::NavigationEntry; | 25 using content::NavigationEntry; |
27 using content::WebContents; | 26 using content::WebContents; |
28 | 27 |
29 LocationIconView::LocationIconView(const gfx::FontList& font_list, | 28 LocationIconView::LocationIconView(const gfx::FontList& font_list, |
30 SkColor parent_background_color, | 29 SkColor parent_background_color, |
31 LocationBarView* location_bar) | 30 LocationBarView* location_bar) |
32 : IconLabelBubbleView(IDR_OMNIBOX_HTTPS_INVALID, | 31 : IconLabelBubbleView(IDR_OMNIBOX_HTTPS_INVALID, |
33 font_list, | 32 font_list, |
34 parent_background_color, | 33 parent_background_color, |
35 true), | 34 true), |
36 suppress_mouse_released_action_(false), | 35 suppress_mouse_released_action_(false), |
37 location_bar_(location_bar) { | 36 location_bar_(location_bar), |
37 animation_(this) { | |
38 set_id(VIEW_ID_LOCATION_ICON); | 38 set_id(VIEW_ID_LOCATION_ICON); |
39 | 39 |
40 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
41 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 41 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
42 #else | 42 #else |
43 SetFocusBehavior(FocusBehavior::ALWAYS); | 43 SetFocusBehavior(FocusBehavior::ALWAYS); |
44 #endif | 44 #endif |
45 | 45 |
46 SetBackground(false); | 46 SetBackground(false); |
47 animation_.SetSlideDuration(kOpenTimeMS); | |
47 } | 48 } |
48 | 49 |
49 LocationIconView::~LocationIconView() { | 50 LocationIconView::~LocationIconView() { |
50 } | 51 } |
51 | 52 |
52 gfx::Size LocationIconView::GetMinimumSize() const { | 53 gfx::Size LocationIconView::GetMinimumSize() const { |
53 return GetMinimumSizeForPreferredSize(GetPreferredSize()); | 54 return GetMinimumSizeForPreferredSize(GetPreferredSize()); |
54 } | 55 } |
55 | 56 |
56 bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) { | 57 bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 } | 98 } |
98 | 99 |
99 bool LocationIconView::GetTooltipText(const gfx::Point& p, | 100 bool LocationIconView::GetTooltipText(const gfx::Point& p, |
100 base::string16* tooltip) const { | 101 base::string16* tooltip) const { |
101 if (show_tooltip_) | 102 if (show_tooltip_) |
102 *tooltip = l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON); | 103 *tooltip = l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON); |
103 return show_tooltip_; | 104 return show_tooltip_; |
104 } | 105 } |
105 | 106 |
106 SkColor LocationIconView::GetTextColor() const { | 107 SkColor LocationIconView::GetTextColor() const { |
107 return location_bar_->GetColor(LocationBarView::EV_BUBBLE_TEXT_AND_BORDER); | 108 return location_bar_->GetColor(LocationBarView::SECURITY_CHIP_TEXT); |
108 } | 109 } |
109 | 110 |
110 SkColor LocationIconView::GetBorderColor() const { | 111 SkColor LocationIconView::GetBorderColor() const { |
111 return GetTextColor(); | 112 return GetTextColor(); |
112 } | 113 } |
113 | 114 |
114 bool LocationIconView::OnActivate(const ui::Event& event) { | 115 bool LocationIconView::OnActivate(const ui::Event& event) { |
115 WebContents* contents = location_bar_->GetWebContents(); | 116 WebContents* contents = location_bar_->GetWebContents(); |
116 if (!contents) | 117 if (!contents) |
117 return false; | 118 return false; |
(...skipping 21 matching lines...) Expand all Loading... | |
139 } | 140 } |
140 | 141 |
141 void LocationIconView::SetBackground(bool should_show_ev) { | 142 void LocationIconView::SetBackground(bool should_show_ev) { |
142 static const int kEvBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_EV_BUBBLE); | 143 static const int kEvBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_EV_BUBBLE); |
143 if (should_show_ev) | 144 if (should_show_ev) |
144 SetBackgroundImageGrid(kEvBackgroundImages); | 145 SetBackgroundImageGrid(kEvBackgroundImages); |
145 else | 146 else |
146 UnsetBackgroundImageGrid(); | 147 UnsetBackgroundImageGrid(); |
147 } | 148 } |
148 | 149 |
150 void LocationIconView::SetSecurityState(bool should_show, bool should_animate) { | |
151 if (!should_animate) { | |
152 animation_.Reset(should_show); | |
153 } else { | |
Peter Kasting
2016/08/30 01:12:42
Nit: Combine else and subsequent if
Kevin Bailey
2016/08/30 14:07:15
Done.
| |
154 if (should_show) | |
155 animation_.Show(); | |
156 else | |
157 animation_.Hide(); | |
158 } | |
159 } | |
160 | |
161 double LocationIconView::WidthMultiplier() const { | |
162 return animation_.GetCurrentValue(); | |
163 } | |
164 | |
165 void LocationIconView::AnimationProgressed(const gfx::Animation*) { | |
166 location_bar_->Layout(); | |
167 location_bar_->SchedulePaint(); | |
168 } | |
169 | |
149 void LocationIconView::ProcessLocatedEvent(const ui::LocatedEvent& event) { | 170 void LocationIconView::ProcessLocatedEvent(const ui::LocatedEvent& event) { |
150 if (HitTestPoint(event.location())) | 171 if (HitTestPoint(event.location())) |
151 OnActivate(event); | 172 OnActivate(event); |
152 } | 173 } |
153 | 174 |
154 gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( | 175 gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( |
155 gfx::Size size) const { | 176 gfx::Size size) const { |
156 const int kMinCharacters = 10; | 177 const int kMinCharacters = 10; |
157 size.SetToMin( | 178 size.SetToMin( |
158 GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters))); | 179 GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters))); |
159 return size; | 180 return size; |
160 } | 181 } |
161 | 182 |
162 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { | 183 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { |
163 // Do not show page info if the user has been editing the location bar or the | 184 // Do not show page info if the user has been editing the location bar or the |
164 // location bar is at the NTP. | 185 // location bar is at the NTP. |
165 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty()) | 186 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty()) |
166 return; | 187 return; |
167 ProcessLocatedEvent(event); | 188 ProcessLocatedEvent(event); |
168 } | 189 } |
OLD | NEW |