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

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

Issue 200783003: [OriginChip] Add animations for the hiding and showing of the chip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to comment Created 6 years, 8 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"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/extensions/extension_icon_image.h" 12 #include "chrome/browser/extensions/extension_icon_image.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/favicon/favicon_tab_helper.h" 14 #include "chrome/browser/favicon/favicon_tab_helper.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
17 #include "chrome/browser/safe_browsing/ui_manager.h" 17 #include "chrome/browser/safe_browsing/ui_manager.h"
18 #include "chrome/browser/search/search.h" 18 #include "chrome/browser/search/search.h"
19 #include "chrome/browser/themes/theme_properties.h" 19 #include "chrome/browser/themes/theme_properties.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/elide_url.h" 21 #include "chrome/browser/ui/elide_url.h"
22 #include "chrome/browser/ui/omnibox/omnibox_view.h" 22 #include "chrome/browser/ui/omnibox/omnibox_view.h"
23 #include "chrome/browser/ui/toolbar/origin_chip_info.h" 23 #include "chrome/browser/ui/toolbar/origin_chip_info.h"
24 #include "chrome/browser/ui/toolbar/toolbar_model.h" 24 #include "chrome/browser/ui/toolbar/toolbar_model.h"
25 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 25 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
26 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
27 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" 27 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
28 #include "content/public/browser/navigation_controller.h"
29 #include "content/public/browser/navigation_entry.h"
30 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
31 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
32 #include "content/public/common/url_constants.h" 30 #include "content/public/common/url_constants.h"
33 #include "extensions/browser/extension_system.h" 31 #include "extensions/browser/extension_system.h"
34 #include "extensions/common/constants.h" 32 #include "extensions/common/constants.h"
35 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
36 #include "grit/theme_resources.h" 34 #include "grit/theme_resources.h"
37 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/resource/resource_bundle.h" 36 #include "ui/base/resource/resource_bundle.h"
39 #include "ui/base/theme_provider.h" 37 #include "ui/base/theme_provider.h"
38 #include "ui/gfx/animation/slide_animation.h"
39 #include "ui/gfx/canvas.h"
40 #include "ui/gfx/font_list.h" 40 #include "ui/gfx/font_list.h"
41 #include "ui/views/background.h" 41 #include "ui/views/background.h"
42 #include "ui/views/controls/button/label_button.h" 42 #include "ui/views/controls/button/label_button.h"
43 #include "ui/views/controls/button/label_button_border.h" 43 #include "ui/views/controls/button/label_button_border.h"
44 #include "ui/views/painter.h" 44 #include "ui/views/painter.h"
45 45
46 46
47 // OriginChipExtensionIcon ---------------------------------------------------- 47 // OriginChipExtensionIcon ----------------------------------------------------
48 48
49 class OriginChipExtensionIcon : public extensions::IconImage::Observer { 49 class OriginChipExtensionIcon : public extensions::IconImage::Observer {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 location_bar_view_(location_bar_view), 136 location_bar_view_(location_bar_view),
137 profile_(profile), 137 profile_(profile),
138 showing_16x16_icon_(false) { 138 showing_16x16_icon_(false) {
139 scoped_refptr<SafeBrowsingService> sb_service = 139 scoped_refptr<SafeBrowsingService> sb_service =
140 g_browser_process->safe_browsing_service(); 140 g_browser_process->safe_browsing_service();
141 // May not be set for unit tests. 141 // May not be set for unit tests.
142 if (sb_service && sb_service->ui_manager()) 142 if (sb_service && sb_service->ui_manager())
143 sb_service->ui_manager()->AddObserver(this); 143 sb_service->ui_manager()->AddObserver(this);
144 144
145 SetFontList(font_list); 145 SetFontList(font_list);
146 }
147 146
148 OriginChipView::~OriginChipView() {
149 scoped_refptr<SafeBrowsingService> sb_service =
150 g_browser_process->safe_browsing_service();
151 if (sb_service.get() && sb_service->ui_manager())
152 sb_service->ui_manager()->RemoveObserver(this);
153 }
154
155 void OriginChipView::Init() {
156 image()->EnableCanvasFlippingForRTLUI(false); 147 image()->EnableCanvasFlippingForRTLUI(false);
157 148
158 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. 149 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here.
159 location_icon_view_ = new LocationIconView(location_bar_view_); 150 location_icon_view_ = new LocationIconView(location_bar_view_);
160 // Make location icon hover events count as hovering the origin chip. 151 // Make location icon hover events count as hovering the origin chip.
161 location_icon_view_->set_interactive(false); 152 location_icon_view_->set_interactive(false);
162 location_icon_view_->ShowTooltip(true); 153 location_icon_view_->ShowTooltip(true);
163 AddChildView(location_icon_view_); 154 AddChildView(location_icon_view_);
164 155
165 host_label_ = new views::Label(base::string16(), GetFontList()); 156 host_label_ = new views::Label(base::string16(), GetFontList());
166 AddChildView(host_label_); 157 AddChildView(host_label_);
158
159 fade_in_animation_.reset(new gfx::SlideAnimation(this));
160 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR);
161 fade_in_animation_->SetSlideDuration(300);
162 }
163
164 OriginChipView::~OriginChipView() {
165 scoped_refptr<SafeBrowsingService> sb_service =
166 g_browser_process->safe_browsing_service();
167 if (sb_service.get() && sb_service->ui_manager())
168 sb_service->ui_manager()->RemoveObserver(this);
167 } 169 }
168 170
169 bool OriginChipView::ShouldShow() { 171 bool OriginChipView::ShouldShow() {
170 return chrome::ShouldDisplayOriginChipV2() && 172 return chrome::ShouldDisplayOriginChipV2() &&
171 location_bar_view_->GetToolbarModel()->WouldOmitURLDueToOriginChip() && 173 location_bar_view_->GetToolbarModel()->WouldOmitURLDueToOriginChip() &&
172 location_bar_view_->GetToolbarModel()->origin_chip_enabled(); 174 location_bar_view_->GetToolbarModel()->origin_chip_enabled();
173 } 175 }
174 176
175 void OriginChipView::Update(content::WebContents* web_contents) { 177 void OriginChipView::Update(content::WebContents* web_contents) {
176 if (!web_contents) 178 if (!web_contents)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 host_label_->SetBackgroundColor( 275 host_label_->SetBackgroundColor(
274 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2)); 276 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2));
275 } 277 }
276 278
277 void OriginChipView::OnChanged() { 279 void OriginChipView::OnChanged() {
278 Update(location_bar_view_->GetWebContents()); 280 Update(location_bar_view_->GetWebContents());
279 // TODO(gbillock): Also need to potentially repaint infobars to make sure the 281 // TODO(gbillock): Also need to potentially repaint infobars to make sure the
280 // arrows are pointing to the right spot. Only needed for some edge cases. 282 // arrows are pointing to the right spot. Only needed for some edge cases.
281 } 283 }
282 284
285 void OriginChipView::FadeIn() {
286 fade_in_animation_->Show();
287 }
288
289 void OriginChipView::AnimationProgressed(const gfx::Animation* animation) {
290 if (animation == fade_in_animation_.get())
291 SchedulePaint();
292 else
293 views::LabelButton::AnimationProgressed(animation);
294 }
295
296 void OriginChipView::AnimationEnded(const gfx::Animation* animation) {
297 if (animation == fade_in_animation_.get())
298 fade_in_animation_->Reset();
299 else
300 views::LabelButton::AnimationEnded(animation);
301 }
302
283 gfx::Size OriginChipView::GetPreferredSize() { 303 gfx::Size OriginChipView::GetPreferredSize() {
284 gfx::Size label_size = host_label_->GetPreferredSize(); 304 gfx::Size label_size = host_label_->GetPreferredSize();
285 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); 305 gfx::Size icon_size = location_icon_view_->GetPreferredSize();
286 int icon_spacing = showing_16x16_icon_ ? 306 int icon_spacing = showing_16x16_icon_ ?
287 (k16x16IconLeadingSpacing + k16x16IconTrailingSpacing) : 0; 307 (k16x16IconLeadingSpacing + k16x16IconTrailingSpacing) : 0;
288 return gfx::Size(kEdgeThickness + icon_size.width() + icon_spacing + 308 return gfx::Size(kEdgeThickness + icon_size.width() + icon_spacing +
289 kIconTextSpacing + label_size.width() + 309 kIconTextSpacing + label_size.width() +
290 kTrailingLabelMargin + kEdgeThickness, 310 kTrailingLabelMargin + kEdgeThickness,
291 icon_size.height()); 311 icon_size.height());
292 } 312 }
(...skipping 12 matching lines...) Expand all
305 kIconTextSpacing; 325 kIconTextSpacing;
306 host_label_x += showing_16x16_icon_ ? k16x16IconTrailingSpacing : 0; 326 host_label_x += showing_16x16_icon_ ? k16x16IconTrailingSpacing : 0;
307 int host_label_width = 327 int host_label_width =
308 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin; 328 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin;
309 host_label_->SetBounds(host_label_x, 329 host_label_->SetBounds(host_label_x,
310 LocationBarView::kNormalEdgeThickness, 330 LocationBarView::kNormalEdgeThickness,
311 host_label_width, 331 host_label_width,
312 height() - 2 * LocationBarView::kNormalEdgeThickness); 332 height() - 2 * LocationBarView::kNormalEdgeThickness);
313 } 333 }
314 334
335 void OriginChipView::OnPaintBorder(gfx::Canvas* canvas) {
336 if (fade_in_animation_->is_animating()) {
337 canvas->SaveLayerAlpha(static_cast<uint8>(
338 fade_in_animation_->CurrentValueBetween(0, 255)));
339 views::LabelButton::OnPaintBorder(canvas);
340 canvas->Restore();
341 } else {
342 views::LabelButton::OnPaintBorder(canvas);
343 }
344 }
345
315 int OriginChipView::ElideDomainTarget(int target_max_width) { 346 int OriginChipView::ElideDomainTarget(int target_max_width) {
316 base::string16 host = 347 base::string16 host =
317 OriginChip::LabelFromURLForProfile(url_displayed_, profile_); 348 OriginChip::LabelFromURLForProfile(url_displayed_, profile_);
318 host_label_->SetText(host); 349 host_label_->SetText(host);
319 int width = GetPreferredSize().width(); 350 int width = GetPreferredSize().width();
320 if (width <= target_max_width) 351 if (width <= target_max_width)
321 return width; 352 return width;
322 353
323 gfx::Size label_size = host_label_->GetPreferredSize(); 354 gfx::Size label_size = host_label_->GetPreferredSize();
324 int padding_width = width - label_size.width(); 355 int padding_width = width - label_size.width();
(...skipping 18 matching lines...) Expand all
343 location_icon_view_->page_info_helper()->ProcessEvent(located_event); 374 location_icon_view_->page_info_helper()->ProcessEvent(located_event);
344 location_icon_view_->set_interactive(false); 375 location_icon_view_->set_interactive(false);
345 return; 376 return;
346 } 377 }
347 location_icon_view_->set_interactive(false); 378 location_icon_view_->set_interactive(false);
348 } 379 }
349 380
350 UMA_HISTOGRAM_COUNTS("OriginChip.Pressed", 1); 381 UMA_HISTOGRAM_COUNTS("OriginChip.Pressed", 1);
351 content::RecordAction(base::UserMetricsAction("OriginChipPress")); 382 content::RecordAction(base::UserMetricsAction("OriginChipPress"));
352 383
353 location_bar_view_->GetOmniboxView()->ShowURL(); 384 location_bar_view_->ShowURL();
354 } 385 }
355 386
356 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will 387 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will
357 // have already been called. 388 // have already been called.
358 void OriginChipView::OnSafeBrowsingHit( 389 void OriginChipView::OnSafeBrowsingHit(
359 const SafeBrowsingUIManager::UnsafeResource& resource) {} 390 const SafeBrowsingUIManager::UnsafeResource& resource) {}
360 391
361 void OriginChipView::OnSafeBrowsingMatch( 392 void OriginChipView::OnSafeBrowsingMatch(
362 const SafeBrowsingUIManager::UnsafeResource& resource) { 393 const SafeBrowsingUIManager::UnsafeResource& resource) {
363 OnChanged(); 394 OnChanged();
364 } 395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698