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

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

Issue 2720183002: [Views] Update ink drop for omnibox icons (Closed)
Patch Set: Nits Created 3 years, 9 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
OLDNEW
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 "chrome/browser/ui/view_ids.h" 7 #include "chrome/browser/ui/view_ids.h"
8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
9 #include "chrome/browser/ui/views/page_info/website_settings_popup_view.h" 9 #include "chrome/browser/ui/views/page_info/website_settings_popup_view.h"
10 #include "chrome/grit/generated_resources.h" 10 #include "chrome/grit/generated_resources.h"
11 #include "chrome/grit/theme_resources.h" 11 #include "chrome/grit/theme_resources.h"
12 #include "components/grit/components_scaled_resources.h" 12 #include "components/grit/components_scaled_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/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/views/controls/label.h" 16 #include "ui/views/controls/label.h"
17 17
18 using content::WebContents; 18 using content::WebContents;
19 19
20 LocationIconView::LocationIconView(const gfx::FontList& font_list, 20 LocationIconView::LocationIconView(const gfx::FontList& font_list,
21 LocationBarView* location_bar) 21 LocationBarView* location_bar)
22 : IconLabelBubbleView(font_list, true), 22 : IconLabelBubbleView(font_list, true),
23 suppress_mouse_released_action_(false),
24 location_bar_(location_bar), 23 location_bar_(location_bar),
25 animation_(this) { 24 animation_(this) {
26 set_id(VIEW_ID_LOCATION_ICON); 25 set_id(VIEW_ID_LOCATION_ICON);
26 SetInkDropMode(InkDropMode::ON);
27 27
28 #if defined(OS_MACOSX) 28 #if defined(OS_MACOSX)
29 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 29 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
30 #else 30 #else
31 SetFocusBehavior(FocusBehavior::ALWAYS); 31 SetFocusBehavior(FocusBehavior::ALWAYS);
32 #endif 32 #endif
33 33
34 animation_.SetSlideDuration(kOpenTimeMS); 34 animation_.SetSlideDuration(kOpenTimeMS);
35 } 35 }
36 36
37 LocationIconView::~LocationIconView() { 37 LocationIconView::~LocationIconView() {
38 } 38 }
39 39
40 gfx::Size LocationIconView::GetMinimumSize() const { 40 gfx::Size LocationIconView::GetMinimumSize() const {
41 return GetMinimumSizeForPreferredSize(GetPreferredSize()); 41 return GetMinimumSizeForPreferredSize(GetPreferredSize());
42 } 42 }
43 43
44 bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) { 44 bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) {
45 if (event.IsOnlyMiddleMouseButton() && 45 if (event.IsOnlyMiddleMouseButton() &&
46 ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) { 46 ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) {
47 base::string16 text; 47 base::string16 text;
48 ui::Clipboard::GetForCurrentThread()->ReadText( 48 ui::Clipboard::GetForCurrentThread()->ReadText(
49 ui::CLIPBOARD_TYPE_SELECTION, &text); 49 ui::CLIPBOARD_TYPE_SELECTION, &text);
50 text = OmniboxView::SanitizeTextForPaste(text); 50 text = OmniboxView::SanitizeTextForPaste(text);
51 OmniboxEditModel* model = location_bar_->GetOmniboxView()->model(); 51 OmniboxEditModel* model = location_bar_->GetOmniboxView()->model();
52 if (model->CanPasteAndGo(text)) 52 if (model->CanPasteAndGo(text))
53 model->PasteAndGo(text); 53 model->PasteAndGo(text);
54 } 54 }
55 55
56 suppress_mouse_released_action_ = 56 IconLabelBubbleView::OnMousePressed(event);
57 WebsiteSettingsPopupView::GetShownPopupType() !=
58 WebsiteSettingsPopupView::POPUP_NONE;
59 return true; 57 return true;
60 } 58 }
61 59
62 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { 60 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) {
63 location_bar_->GetOmniboxView()->CloseOmniboxPopup(); 61 location_bar_->GetOmniboxView()->CloseOmniboxPopup();
64 return false; 62 return IconLabelBubbleView::OnMouseDragged(event);
65 }
66
67 void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) {
68 if (event.IsOnlyMiddleMouseButton())
69 return;
70
71 // If this is the second click on this view then the bubble was showing on
72 // the mouse pressed event and is hidden now. Prevent the bubble from
73 // reshowing by doing nothing here.
74 if (suppress_mouse_released_action_) {
75 suppress_mouse_released_action_ = false;
76 return;
77 }
78
79 OnClickOrTap(event);
80 }
81
82 void LocationIconView::OnGestureEvent(ui::GestureEvent* event) {
83 if (event->type() != ui::ET_GESTURE_TAP)
84 return;
85 OnClickOrTap(*event);
86 event->SetHandled();
87 } 63 }
88 64
89 bool LocationIconView::GetTooltipText(const gfx::Point& p, 65 bool LocationIconView::GetTooltipText(const gfx::Point& p,
90 base::string16* tooltip) const { 66 base::string16* tooltip) const {
91 if (show_tooltip_) 67 if (show_tooltip_)
92 *tooltip = l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON); 68 *tooltip = l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON);
93 return show_tooltip_; 69 return show_tooltip_;
94 } 70 }
95 71
96 SkColor LocationIconView::GetTextColor() const { 72 SkColor LocationIconView::GetTextColor() const {
97 return location_bar_->GetColor(LocationBarView::SECURITY_CHIP_TEXT); 73 return location_bar_->GetColor(LocationBarView::SECURITY_CHIP_TEXT);
98 } 74 }
99 75
100 bool LocationIconView::OnActivate(const ui::Event& event) { 76 bool LocationIconView::OnActivate(const ui::Event& event) {
101 WebContents* contents = location_bar_->GetWebContents(); 77 WebContents* contents = location_bar_->GetWebContents();
102 if (!contents) 78 if (!contents)
103 return false; 79 return false;
104 location_bar_->delegate()->ShowWebsiteSettings(contents); 80 location_bar_->delegate()->ShowWebsiteSettings(contents);
105 return true; 81 return true;
106 } 82 }
107 83
108 void LocationIconView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 84 void LocationIconView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
109 IconLabelBubbleView::GetAccessibleNodeData(node_data); 85 IconLabelBubbleView::GetAccessibleNodeData(node_data);
110 node_data->role = ui::AX_ROLE_POP_UP_BUTTON; 86 node_data->role = ui::AX_ROLE_POP_UP_BUTTON;
111 } 87 }
112 88
89 bool LocationIconView::IsBubbleShown() const {
90 return WebsiteSettingsPopupView::GetShownPopupType() !=
91 WebsiteSettingsPopupView::POPUP_NONE;
92 }
93
113 gfx::Size LocationIconView::GetMinimumSizeForLabelText( 94 gfx::Size LocationIconView::GetMinimumSizeForLabelText(
114 const base::string16& text) const { 95 const base::string16& text) const {
115 views::Label label(text, {font_list()}); 96 views::Label label(text, {font_list()});
116 return GetMinimumSizeForPreferredSize( 97 return GetMinimumSizeForPreferredSize(
117 GetSizeForLabelWidth(label.GetPreferredSize().width())); 98 GetSizeForLabelWidth(label.GetPreferredSize().width()));
118 } 99 }
119 100
120 void LocationIconView::SetTextVisibility(bool should_show, 101 void LocationIconView::SetTextVisibility(bool should_show,
121 bool should_animate) { 102 bool should_animate) {
122 if (!should_animate) { 103 if (!should_animate) {
123 animation_.Reset(should_show); 104 animation_.Reset(should_show);
124 } else if (should_show) { 105 } else if (should_show) {
125 animation_.Show(); 106 animation_.Show();
126 } else { 107 } else {
127 animation_.Hide(); 108 animation_.Hide();
128 } 109 }
129 // The label text color may have changed. 110 // The label text color may have changed.
130 OnNativeThemeChanged(GetNativeTheme()); 111 OnNativeThemeChanged(GetNativeTheme());
131 } 112 }
132 113
114 bool LocationIconView::IsTriggerableEvent(const ui::Event& event) {
115 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty())
116 return false;
117
118 if (event.IsMouseEvent()) {
119 const ui::MouseEvent& mouseev = static_cast<const ui::MouseEvent&>(event);
120 if (mouseev.IsOnlyMiddleMouseButton())
121 return false;
122 } else if (event.IsGestureEvent() && event.type() != ui::ET_GESTURE_TAP) {
123 return false;
124 }
125
126 return IconLabelBubbleView::IsTriggerableEvent(event);
127 }
128
133 double LocationIconView::WidthMultiplier() const { 129 double LocationIconView::WidthMultiplier() const {
134 return animation_.GetCurrentValue(); 130 return animation_.GetCurrentValue();
135 } 131 }
136 132
137 void LocationIconView::AnimationProgressed(const gfx::Animation*) { 133 void LocationIconView::AnimationProgressed(const gfx::Animation*) {
138 location_bar_->Layout(); 134 location_bar_->Layout();
139 location_bar_->SchedulePaint(); 135 location_bar_->SchedulePaint();
140 } 136 }
141 137
142 void LocationIconView::ProcessLocatedEvent(const ui::LocatedEvent& event) {
143 if (HitTestPoint(event.location()))
144 OnActivate(event);
145 }
146
147 gfx::Size LocationIconView::GetMinimumSizeForPreferredSize( 138 gfx::Size LocationIconView::GetMinimumSizeForPreferredSize(
148 gfx::Size size) const { 139 gfx::Size size) const {
149 const int kMinCharacters = 10; 140 const int kMinCharacters = 10;
150 size.SetToMin( 141 size.SetToMin(
151 GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters))); 142 GetSizeForLabelWidth(font_list().GetExpectedTextWidth(kMinCharacters)));
152 return size; 143 return size;
153 } 144 }
154
155 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) {
156 // Do not show page info if the user has been editing the location bar or the
157 // location bar is at the NTP.
158 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty())
159 return;
160 ProcessLocatedEvent(event);
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698