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 if (should_show) { |
| 154 animation_.Show(); |
| 155 } else { |
| 156 animation_.Hide(); |
| 157 } |
| 158 } |
| 159 |
| 160 double LocationIconView::WidthMultiplier() const { |
| 161 return animation_.GetCurrentValue(); |
| 162 } |
| 163 |
| 164 void LocationIconView::AnimationProgressed(const gfx::Animation*) { |
| 165 location_bar_->Layout(); |
| 166 location_bar_->SchedulePaint(); |
| 167 } |
| 168 |
149 void LocationIconView::ProcessLocatedEvent(const ui::LocatedEvent& event) { | 169 void LocationIconView::ProcessLocatedEvent(const ui::LocatedEvent& event) { |
150 if (HitTestPoint(event.location())) | 170 if (HitTestPoint(event.location())) |
151 OnActivate(event); | 171 OnActivate(event); |
152 } | 172 } |
153 | 173 |
154 gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( | 174 gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( |
155 gfx::Size size) const { | 175 gfx::Size size) const { |
156 const int kMinCharacters = 10; | 176 const int kMinCharacters = 10; |
157 size.SetToMin( | 177 size.SetToMin( |
158 GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters))); | 178 GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters))); |
159 return size; | 179 return size; |
160 } | 180 } |
161 | 181 |
162 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { | 182 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { |
163 // Do not show page info if the user has been editing the location bar or the | 183 // Do not show page info if the user has been editing the location bar or the |
164 // location bar is at the NTP. | 184 // location bar is at the NTP. |
165 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty()) | 185 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty()) |
166 return; | 186 return; |
167 ProcessLocatedEvent(event); | 187 ProcessLocatedEvent(event); |
168 } | 188 } |
OLD | NEW |