Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/ui/views/location_bar/origin_chip_view.cc

Issue 302453002: New animation for the origin chip URL showing/hiding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test failure by checking for NULL extension Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/origin_chip_view.h" 5 #include "chrome/browser/ui/views/location_bar/origin_chip_view.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 18 matching lines...) Expand all
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/url_constants.h" 30 #include "content/public/common/url_constants.h"
31 #include "extensions/browser/extension_system.h" 31 #include "extensions/browser/extension_system.h"
32 #include "extensions/common/constants.h" 32 #include "extensions/common/constants.h"
33 #include "extensions/common/manifest_handlers/icons_handler.h" 33 #include "extensions/common/manifest_handlers/icons_handler.h"
34 #include "grit/generated_resources.h" 34 #include "grit/generated_resources.h"
35 #include "grit/theme_resources.h" 35 #include "grit/theme_resources.h"
36 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
38 #include "ui/base/theme_provider.h" 38 #include "ui/base/theme_provider.h"
39 #include "ui/gfx/animation/slide_animation.h"
40 #include "ui/gfx/canvas.h" 39 #include "ui/gfx/canvas.h"
41 #include "ui/gfx/font_list.h" 40 #include "ui/gfx/font_list.h"
41 #include "ui/gfx/text_utils.h"
42 #include "ui/views/background.h" 42 #include "ui/views/background.h"
43 #include "ui/views/controls/button/label_button.h" 43 #include "ui/views/controls/button/label_button.h"
44 #include "ui/views/controls/button/label_button_border.h" 44 #include "ui/views/controls/button/label_button_border.h"
45 #include "ui/views/painter.h" 45 #include "ui/views/painter.h"
46 46
47 47
48 // OriginChipExtensionIcon ---------------------------------------------------- 48 // OriginChipExtensionIcon ----------------------------------------------------
49 49
50 class OriginChipExtensionIcon : public extensions::IconImage::Observer { 50 class OriginChipExtensionIcon : public extensions::IconImage::Observer {
51 public: 51 public:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 96
97 // OriginChipView ------------------------------------------------------------- 97 // OriginChipView -------------------------------------------------------------
98 98
99 namespace { 99 namespace {
100 100
101 const int kEdgeThickness = 5; 101 const int kEdgeThickness = 5;
102 const int k16x16IconLeadingSpacing = 1; 102 const int k16x16IconLeadingSpacing = 1;
103 const int k16x16IconTrailingSpacing = 2; 103 const int k16x16IconTrailingSpacing = 2;
104 const int kIconTextSpacing = 3; 104 const int kIconTextSpacing = 3;
105 const int kTrailingLabelMargin = 0;
106 105
107 const int kNormalImages[3][9] = { 106 const int kNormalImages[3][9] = {
108 IMAGE_GRID(IDR_ORIGIN_CHIP_NORMAL), 107 IMAGE_GRID(IDR_ORIGIN_CHIP_NORMAL),
109 IMAGE_GRID(IDR_ORIGIN_CHIP_HOVER), 108 IMAGE_GRID(IDR_ORIGIN_CHIP_HOVER),
110 IMAGE_GRID(IDR_ORIGIN_CHIP_PRESSED) 109 IMAGE_GRID(IDR_ORIGIN_CHIP_PRESSED)
111 }; 110 };
112 111
113 const int kMalwareImages[3][9] = { 112 const int kMalwareImages[3][9] = {
114 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_NORMAL), 113 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_NORMAL),
115 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_HOVER), 114 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_HOVER),
116 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_PRESSED) 115 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_PRESSED)
117 }; 116 };
118 117
119 const int kBrokenSSLImages[3][9] = { 118 const int kBrokenSSLImages[3][9] = {
120 IMAGE_GRID(IDR_ORIGIN_CHIP_BROKENSSL_NORMAL), 119 IMAGE_GRID(IDR_ORIGIN_CHIP_BROKENSSL_NORMAL),
121 IMAGE_GRID(IDR_ORIGIN_CHIP_BROKENSSL_HOVER), 120 IMAGE_GRID(IDR_ORIGIN_CHIP_BROKENSSL_HOVER),
122 IMAGE_GRID(IDR_ORIGIN_CHIP_BROKENSSL_PRESSED) 121 IMAGE_GRID(IDR_ORIGIN_CHIP_BROKENSSL_PRESSED)
123 }; 122 };
124 123
125 const int kEVImages[3][9] = { 124 const int kEVImages[3][9] = {
126 IMAGE_GRID(IDR_ORIGIN_CHIP_EV_NORMAL), 125 IMAGE_GRID(IDR_ORIGIN_CHIP_EV_NORMAL),
127 IMAGE_GRID(IDR_ORIGIN_CHIP_EV_HOVER), 126 IMAGE_GRID(IDR_ORIGIN_CHIP_EV_HOVER),
128 IMAGE_GRID(IDR_ORIGIN_CHIP_EV_PRESSED) 127 IMAGE_GRID(IDR_ORIGIN_CHIP_EV_PRESSED)
129 }; 128 };
130 129
130 const extensions::Extension* GetExtension(const GURL& url, Profile* profile) {
131 if (!url.SchemeIs(extensions::kExtensionScheme))
132 return NULL;
133 ExtensionService* service =
134 extensions::ExtensionSystem::Get(profile)->extension_service();
135 return service->extensions()->GetExtensionOrAppByURL(url);
136 }
137
131 } // namespace 138 } // namespace
132 139
133 OriginChipView::OriginChipView(LocationBarView* location_bar_view, 140 OriginChipView::OriginChipView(LocationBarView* location_bar_view,
134 Profile* profile, 141 Profile* profile,
135 const gfx::FontList& font_list) 142 const gfx::FontList& font_list)
136 : LabelButton(this, base::string16()), 143 : LabelButton(this, base::string16()),
137 location_bar_view_(location_bar_view), 144 location_bar_view_(location_bar_view),
138 profile_(profile), 145 profile_(profile),
139 showing_16x16_icon_(false) { 146 showing_16x16_icon_(false),
147 fade_in_animation_(this) {
140 scoped_refptr<SafeBrowsingService> sb_service = 148 scoped_refptr<SafeBrowsingService> sb_service =
141 g_browser_process->safe_browsing_service(); 149 g_browser_process->safe_browsing_service();
142 // May not be set for unit tests. 150 // May not be set for unit tests.
143 if (sb_service && sb_service->ui_manager()) 151 if (sb_service && sb_service->ui_manager())
144 sb_service->ui_manager()->AddObserver(this); 152 sb_service->ui_manager()->AddObserver(this);
145 153
146 SetFontList(font_list); 154 SetFontList(font_list);
147 155
148 image()->EnableCanvasFlippingForRTLUI(false); 156 image()->EnableCanvasFlippingForRTLUI(false);
149 157
150 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. 158 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here.
151 location_icon_view_ = new LocationIconView(location_bar_view_); 159 location_icon_view_ = new LocationIconView(location_bar_view_);
152 // Make location icon hover events count as hovering the origin chip. 160 // Make location icon hover events count as hovering the origin chip.
153 location_icon_view_->set_interactive(false); 161 location_icon_view_->set_interactive(false);
154 location_icon_view_->ShowTooltip(true); 162 location_icon_view_->ShowTooltip(true);
155 AddChildView(location_icon_view_); 163 AddChildView(location_icon_view_);
156 164
165 ev_label_ = new views::Label(base::string16(), GetFontList());
166 ev_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
167 ev_label_->SetElideBehavior(views::Label::NO_ELIDE);
168 AddChildView(ev_label_);
169
157 host_label_ = new views::Label(base::string16(), GetFontList()); 170 host_label_ = new views::Label(base::string16(), GetFontList());
171 host_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
172 host_label_->SetElideBehavior(views::Label::NO_ELIDE);
158 AddChildView(host_label_); 173 AddChildView(host_label_);
159 174
160 fade_in_animation_.reset(new gfx::SlideAnimation(this)); 175 fade_in_animation_.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN);
161 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR); 176 fade_in_animation_.SetSlideDuration(175);
162 fade_in_animation_->SetSlideDuration(300);
163 } 177 }
164 178
165 OriginChipView::~OriginChipView() { 179 OriginChipView::~OriginChipView() {
166 scoped_refptr<SafeBrowsingService> sb_service = 180 scoped_refptr<SafeBrowsingService> sb_service =
167 g_browser_process->safe_browsing_service(); 181 g_browser_process->safe_browsing_service();
168 if (sb_service.get() && sb_service->ui_manager()) 182 if (sb_service.get() && sb_service->ui_manager())
169 sb_service->ui_manager()->RemoveObserver(this); 183 sb_service->ui_manager()->RemoveObserver(this);
170 } 184 }
171 185
172 void OriginChipView::Update(content::WebContents* web_contents) { 186 void OriginChipView::OnChanged() {
187 content::WebContents* web_contents = location_bar_view_->GetWebContents();
173 if (!web_contents) 188 if (!web_contents)
174 return; 189 return;
175 190
176 // Note: security level can change async as the connection is made. 191 // Note: security level can change async as the connection is made.
177 GURL url = location_bar_view_->GetToolbarModel()->GetURL(); 192 GURL url = location_bar_view_->GetToolbarModel()->GetURL();
178 const ToolbarModel::SecurityLevel security_level = 193 const ToolbarModel::SecurityLevel security_level =
179 location_bar_view_->GetToolbarModel()->GetSecurityLevel(true); 194 location_bar_view_->GetToolbarModel()->GetSecurityLevel(true);
180 195
181 bool url_malware = OriginChip::IsMalware(url, web_contents); 196 bool url_malware = OriginChip::IsMalware(url, web_contents);
182 197
(...skipping 13 matching lines...) Expand all
196 if (url_malware_) { 211 if (url_malware_) {
197 SetBorderImages(kMalwareImages); 212 SetBorderImages(kMalwareImages);
198 } else if (security_level_ == ToolbarModel::SECURITY_ERROR) { 213 } else if (security_level_ == ToolbarModel::SECURITY_ERROR) {
199 SetBorderImages(kBrokenSSLImages); 214 SetBorderImages(kBrokenSSLImages);
200 } else if (security_level_ == ToolbarModel::EV_SECURE) { 215 } else if (security_level_ == ToolbarModel::EV_SECURE) {
201 SetBorderImages(kEVImages); 216 SetBorderImages(kEVImages);
202 } else { 217 } else {
203 SetBorderImages(kNormalImages); 218 SetBorderImages(kNormalImages);
204 } 219 }
205 220
221 ev_label_->SetText(location_bar_view_->GetToolbarModel()->GetEVCertName());
222 ev_label_->SetVisible(security_level_ == ToolbarModel::EV_SECURE);
223
224 // TODO(pkasting): Allow the origin chip to shrink, and use ElideHost().
206 base::string16 host = 225 base::string16 host =
207 OriginChip::LabelFromURLForProfile(url_displayed_, profile_); 226 OriginChip::LabelFromURLForProfile(url_displayed_, profile_);
208 if (security_level_ == ToolbarModel::EV_SECURE) {
209 host = l10n_util::GetStringFUTF16(IDS_SITE_CHIP_EV_SSL_LABEL,
210 location_bar_view_->GetToolbarModel()->GetEVCertName(),
211 host);
212 }
213 host_label_->SetText(host); 227 host_label_->SetText(host);
214 host_label_->SetTooltipText(base::UTF8ToUTF16(url.spec())); 228 host_label_->SetTooltipText(base::UTF8ToUTF16(url.spec()));
215 host_label_->SetElideBehavior(views::Label::NO_ELIDE);
216 229
217 int icon = location_bar_view_->GetToolbarModel()->GetIconForSecurityLevel( 230 showing_16x16_icon_ = url_displayed_.is_empty() ||
218 security_level_); 231 url_displayed_.SchemeIs(content::kChromeUIScheme);
219 showing_16x16_icon_ = false; 232 int icon = showing_16x16_icon_ ? IDR_PRODUCT_LOGO_16 :
220 233 location_bar_view_->GetToolbarModel()->GetIconForSecurityLevel(
221 if (url_displayed_.is_empty() || 234 security_level_);
222 url_displayed_.SchemeIs(content::kChromeUIScheme)) { 235 const extensions::Extension* extension =
223 icon = IDR_PRODUCT_LOGO_16; 236 GetExtension(url_displayed_, profile_);
224 showing_16x16_icon_ = true; 237 if (extension) {
225 }
226
227 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon));
228
229 if (url_displayed_.SchemeIs(extensions::kExtensionScheme)) {
230 icon = IDR_EXTENSIONS_FAVICON; 238 icon = IDR_EXTENSIONS_FAVICON;
231 showing_16x16_icon_ = true; 239 showing_16x16_icon_ = true;
232 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon));
233
234 ExtensionService* service =
235 extensions::ExtensionSystem::Get(profile_)->extension_service();
236 const extensions::Extension* extension =
237 service->extensions()->GetExtensionOrAppByURL(url_displayed_);
238 extension_icon_.reset( 240 extension_icon_.reset(
239 new OriginChipExtensionIcon(location_icon_view_, profile_, extension)); 241 new OriginChipExtensionIcon(location_icon_view_, profile_, extension));
240 } else { 242 } else {
241 extension_icon_.reset(); 243 extension_icon_.reset();
242 } 244 }
245 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon));
243 246
244 Layout(); 247 if (visible()) {
245 SchedulePaint(); 248 CancelFade();
246 } 249 Layout();
247 250 SchedulePaint();
248 void OriginChipView::OnChanged() { 251 }
249 Update(location_bar_view_->GetWebContents());
250 // TODO(gbillock): Also need to potentially repaint infobars to make sure the
251 // arrows are pointing to the right spot. Only needed for some edge cases.
252 }
253
254 int OriginChipView::ElideDomainTarget(int target_max_width) {
255 base::string16 host =
256 OriginChip::LabelFromURLForProfile(url_displayed_, profile_);
257 host_label_->SetText(host);
258 int width = GetPreferredSize().width();
259 if (width <= target_max_width)
260 return width;
261
262 gfx::Size label_size = host_label_->GetPreferredSize();
263 int padding_width = width - label_size.width();
264
265 host_label_->SetText(ElideHost(
266 location_bar_view_->GetToolbarModel()->GetURL(),
267 host_label_->font_list(), target_max_width - padding_width));
268 return GetPreferredSize().width();
269 } 252 }
270 253
271 void OriginChipView::FadeIn() { 254 void OriginChipView::FadeIn() {
272 fade_in_animation_->Show(); 255 fade_in_animation_.Show();
256 }
257
258 void OriginChipView::CancelFade() {
259 fade_in_animation_.Stop();
260 }
261
262 int OriginChipView::HostLabelOffset() const {
263 return host_label_->x() - GetLabelX();
264 }
265
266 int OriginChipView::WidthFromStartOfLabels() const {
267 return width() - GetLabelX();
273 } 268 }
274 269
275 gfx::Size OriginChipView::GetPreferredSize() const { 270 gfx::Size OriginChipView::GetPreferredSize() const {
276 gfx::Size label_size = host_label_->GetPreferredSize(); 271 // TODO(pkasting): Use of " " here is a horrible hack, to be replaced by
277 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); 272 // splitting the chip into separate pieces for EV/host.
278 int icon_spacing = showing_16x16_icon_ ? 273 int label_size = host_label_->GetPreferredSize().width();
279 (k16x16IconLeadingSpacing + k16x16IconTrailingSpacing) : 0; 274 if (ev_label_->visible()) {
280 return gfx::Size(kEdgeThickness + icon_size.width() + icon_spacing + 275 label_size += ev_label_->GetPreferredSize().width() +
281 kIconTextSpacing + label_size.width() + 276 gfx::GetStringWidth(base::ASCIIToUTF16(" "), GetFontList());
282 kTrailingLabelMargin + kEdgeThickness, 277 }
283 icon_size.height()); 278 return gfx::Size(GetLabelX() + label_size + kEdgeThickness,
284 } 279 location_icon_view_->GetPreferredSize().height());
285
286 void OriginChipView::SetBorderImages(const int images[3][9]) {
287 scoped_ptr<views::LabelButtonBorder> border(
288 new views::LabelButtonBorder(views::Button::STYLE_BUTTON));
289
290 views::Painter* painter = views::Painter::CreateImageGridPainter(images[0]);
291 border->SetPainter(false, Button::STATE_NORMAL, painter);
292 painter = views::Painter::CreateImageGridPainter(images[1]);
293 border->SetPainter(false, Button::STATE_HOVERED, painter);
294 painter = views::Painter::CreateImageGridPainter(images[2]);
295 border->SetPainter(false, Button::STATE_PRESSED, painter);
296
297 SetBorder(border.PassAs<views::Border>());
298
299 // Calculate a representative background color of the provided image grid and
300 // set it as the background color of the host label in order to color the text
301 // appropriately. We grab the color of the middle pixel of the middle image
302 // of the background, which we treat as the representative color of the entire
303 // background (reasonable, given the current appearance of these images).
304 const SkBitmap& bitmap(
305 GetThemeProvider()->GetImageSkiaNamed(
306 images[0][4])->GetRepresentation(1.0f).sk_bitmap());
307 SkAutoLockPixels pixel_lock(bitmap);
308 host_label_->SetBackgroundColor(
309 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2));
310 }
311
312 void OriginChipView::AnimationProgressed(const gfx::Animation* animation) {
313 if (animation == fade_in_animation_.get())
314 SchedulePaint();
315 else
316 views::LabelButton::AnimationProgressed(animation);
317 }
318
319 void OriginChipView::AnimationEnded(const gfx::Animation* animation) {
320 if (animation == fade_in_animation_.get())
321 fade_in_animation_->Reset();
322 else
323 views::LabelButton::AnimationEnded(animation);
324 } 280 }
325 281
326 void OriginChipView::Layout() { 282 void OriginChipView::Layout() {
327 // TODO(gbillock): Eventually we almost certainly want to use 283 // TODO(gbillock): Eventually we almost certainly want to use
328 // LocationBarLayout for leading and trailing decorations. 284 // LocationBarLayout for leading and trailing decorations.
329 285
330 location_icon_view_->SetBounds( 286 location_icon_view_->SetBounds(
331 kEdgeThickness + (showing_16x16_icon_ ? k16x16IconLeadingSpacing : 0), 287 kEdgeThickness + (showing_16x16_icon_ ? k16x16IconLeadingSpacing : 0),
332 LocationBarView::kNormalEdgeThickness, 288 LocationBarView::kNormalEdgeThickness,
333 location_icon_view_->GetPreferredSize().width(), 289 location_icon_view_->GetPreferredSize().width(),
334 height() - 2 * LocationBarView::kNormalEdgeThickness); 290 height() - 2 * LocationBarView::kNormalEdgeThickness);
335 291
336 int host_label_x = location_icon_view_->x() + location_icon_view_->width() + 292 int label_x = GetLabelX();
337 kIconTextSpacing; 293 int label_width = std::max(0, width() - label_x - kEdgeThickness);
338 host_label_x += showing_16x16_icon_ ? k16x16IconTrailingSpacing : 0; 294 const int label_y = LocationBarView::kNormalEdgeThickness;
339 int host_label_width = 295 const int label_height = height() - 2 * LocationBarView::kNormalEdgeThickness;
340 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin; 296 if (ev_label_->visible()) {
341 host_label_->SetBounds(host_label_x, 297 int ev_label_width =
342 LocationBarView::kNormalEdgeThickness, 298 std::min(ev_label_->GetPreferredSize().width(), label_width);
343 host_label_width, 299 ev_label_->SetBounds(label_x, label_y, ev_label_width, label_height);
344 height() - 2 * LocationBarView::kNormalEdgeThickness); 300 // TODO(pkasting): See comments in GetPreferredSize().
301 ev_label_width +=
302 gfx::GetStringWidth(base::ASCIIToUTF16(" "), GetFontList());
303 label_x += ev_label_width;
304 label_width = std::max(0, label_width - ev_label_width);
305 }
306 host_label_->SetBounds(label_x, label_y, label_width, label_height);
307 }
308
309 int OriginChipView::GetLabelX() const {
310 const int icon_spacing = showing_16x16_icon_ ?
311 (k16x16IconLeadingSpacing + k16x16IconTrailingSpacing) : 0;
312 return kEdgeThickness + location_icon_view_->GetPreferredSize().width() +
313 icon_spacing + kIconTextSpacing;
314 }
315
316 void OriginChipView::SetBorderImages(const int images[3][9]) {
317 scoped_ptr<views::LabelButtonBorder> border(
318 new views::LabelButtonBorder(views::Button::STYLE_BUTTON));
319
320 for (size_t i = 0; i < 3; ++i) {
321 views::Painter* painter = views::Painter::CreateImageGridPainter(images[i]);
322 border->SetPainter(false, static_cast<Button::ButtonState>(i), painter);
323
324 // Calculate a representative background color of the provided image grid to
325 // use as the background color of the host label in order to color the text
326 // appropriately. We grab the color of the middle pixel of the middle image
327 // of the background, which we treat as the representative color of the
328 // entire background (reasonable, given the current appearance of these
329 // images).
330 const SkBitmap& bitmap(
331 GetThemeProvider()->GetImageSkiaNamed(
332 images[i][4])->GetRepresentation(1.0f).sk_bitmap());
333 SkAutoLockPixels pixel_lock(bitmap);
334 background_colors_[i] =
335 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2);
336 }
337
338 // Calculate the actual text color of the pressed label.
339 host_label_->SetBackgroundColor(background_colors_[Button::STATE_PRESSED]);
340 pressed_text_color_ = host_label_->enabled_color();
341 host_label_->SetBackgroundColor(background_colors_[state()]);
342
343 SetBorder(border.PassAs<views::Border>());
344 }
345
346 void OriginChipView::AnimationProgressed(const gfx::Animation* animation) {
347 if (animation == &fade_in_animation_)
348 SchedulePaint();
349 else
350 views::LabelButton::AnimationProgressed(animation);
351 }
352
353 void OriginChipView::AnimationEnded(const gfx::Animation* animation) {
354 if (animation == &fade_in_animation_)
355 fade_in_animation_.Reset();
356 else
357 views::LabelButton::AnimationEnded(animation);
345 } 358 }
346 359
347 void OriginChipView::OnPaintBorder(gfx::Canvas* canvas) { 360 void OriginChipView::OnPaintBorder(gfx::Canvas* canvas) {
348 if (fade_in_animation_->is_animating()) { 361 if (fade_in_animation_.is_animating()) {
349 canvas->SaveLayerAlpha(static_cast<uint8>( 362 canvas->SaveLayerAlpha(static_cast<uint8>(
350 fade_in_animation_->CurrentValueBetween(0, 255))); 363 fade_in_animation_.CurrentValueBetween(0, 255)));
351 views::LabelButton::OnPaintBorder(canvas); 364 views::LabelButton::OnPaintBorder(canvas);
352 canvas->Restore(); 365 canvas->Restore();
353 } else { 366 } else {
354 views::LabelButton::OnPaintBorder(canvas); 367 views::LabelButton::OnPaintBorder(canvas);
355 } 368 }
356 } 369 }
357 370
371 void OriginChipView::StateChanged() {
372 DCHECK_LT(state(), 3);
373 SkColor background_color = background_colors_[state()];
374 ev_label_->SetBackgroundColor(background_color);
375 host_label_->SetBackgroundColor(background_color);
376 }
377
358 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for 378 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for
359 // this button. 379 // this button.
360 void OriginChipView::ButtonPressed(views::Button* sender, 380 void OriginChipView::ButtonPressed(views::Button* sender,
361 const ui::Event& event) { 381 const ui::Event& event) {
362 // See if the event needs to be passed to the LocationIconView. 382 // See if the event needs to be passed to the LocationIconView.
363 if (event.IsMouseEvent() || (event.type() == ui::ET_GESTURE_TAP)) { 383 if (event.IsMouseEvent() || (event.type() == ui::ET_GESTURE_TAP)) {
364 location_icon_view_->set_interactive(true); 384 location_icon_view_->set_interactive(true);
365 const ui::LocatedEvent& located_event = 385 const ui::LocatedEvent& located_event =
366 static_cast<const ui::LocatedEvent&>(event); 386 static_cast<const ui::LocatedEvent&>(event);
367 if (GetEventHandlerForPoint(located_event.location()) == 387 if (GetEventHandlerForPoint(located_event.location()) ==
(...skipping 13 matching lines...) Expand all
381 401
382 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will 402 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will
383 // have already been called. 403 // have already been called.
384 void OriginChipView::OnSafeBrowsingHit( 404 void OriginChipView::OnSafeBrowsingHit(
385 const SafeBrowsingUIManager::UnsafeResource& resource) {} 405 const SafeBrowsingUIManager::UnsafeResource& resource) {}
386 406
387 void OriginChipView::OnSafeBrowsingMatch( 407 void OriginChipView::OnSafeBrowsingMatch(
388 const SafeBrowsingUIManager::UnsafeResource& resource) { 408 const SafeBrowsingUIManager::UnsafeResource& resource) {
389 OnChanged(); 409 OnChanged();
390 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698