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

Side by Side Diff: chrome/browser/ui/views/find_bar_view.cc

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: tests 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/find_bar_view.h" 5 #include "chrome/browser/ui/views/find_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/number_formatting.h" 9 #include "base/i18n/number_formatting.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 18 matching lines...) Expand all
29 #include "ui/base/theme_provider.h" 29 #include "ui/base/theme_provider.h"
30 #include "ui/events/event.h" 30 #include "ui/events/event.h"
31 #include "ui/gfx/color_palette.h" 31 #include "ui/gfx/color_palette.h"
32 #include "ui/gfx/paint_vector_icon.h" 32 #include "ui/gfx/paint_vector_icon.h"
33 #include "ui/native_theme/native_theme.h" 33 #include "ui/native_theme/native_theme.h"
34 #include "ui/vector_icons/vector_icons.h" 34 #include "ui/vector_icons/vector_icons.h"
35 #include "ui/views/background.h" 35 #include "ui/views/background.h"
36 #include "ui/views/border.h" 36 #include "ui/views/border.h"
37 #include "ui/views/bubble/bubble_border.h" 37 #include "ui/views/bubble/bubble_border.h"
38 #include "ui/views/controls/button/image_button.h" 38 #include "ui/views/controls/button/image_button.h"
39 #include "ui/views/controls/button/vector_icon_button.h" 39 #include "ui/views/controls/button/image_button_util.h"
40 #include "ui/views/controls/label.h" 40 #include "ui/views/controls/label.h"
41 #include "ui/views/controls/separator.h" 41 #include "ui/views/controls/separator.h"
42 #include "ui/views/layout/box_layout.h" 42 #include "ui/views/layout/box_layout.h"
43 #include "ui/views/painter.h" 43 #include "ui/views/painter.h"
44 #include "ui/views/view_targeter.h" 44 #include "ui/views/view_targeter.h"
45 #include "ui/views/widget/widget.h" 45 #include "ui/views/widget/widget.h"
46 46
47 namespace { 47 namespace {
48 48
49 // These layout constants are all in dp. 49 // These layout constants are all in dp.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 //////////////////////////////////////////////////////////////////////////////// 111 ////////////////////////////////////////////////////////////////////////////////
112 // FindBarView, public: 112 // FindBarView, public:
113 113
114 FindBarView::FindBarView(FindBarHost* host) 114 FindBarView::FindBarView(FindBarHost* host)
115 : find_bar_host_(host), 115 : find_bar_host_(host),
116 find_text_(new views::Textfield), 116 find_text_(new views::Textfield),
117 match_count_text_(new MatchCountLabel()), 117 match_count_text_(new MatchCountLabel()),
118 focus_forwarder_view_(new FocusForwarderView(find_text_)), 118 focus_forwarder_view_(new FocusForwarderView(find_text_)),
119 separator_(new views::Separator()), 119 separator_(new views::Separator()),
120 find_previous_button_(new views::VectorIconButton(this)), 120 find_previous_button_(
121 find_next_button_(new views::VectorIconButton(this)), 121 views::CreateImageButtonWithVectorIconStyling(this)),
122 close_button_(new views::VectorIconButton(this)) { 122 find_next_button_(views::CreateImageButtonWithVectorIconStyling(this)),
123 close_button_(views::CreateImageButtonWithVectorIconStyling(this)) {
123 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); 124 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
124 find_text_->set_default_width_in_chars(kDefaultCharWidth); 125 find_text_->set_default_width_in_chars(kDefaultCharWidth);
125 find_text_->set_controller(this); 126 find_text_->set_controller(this);
126 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); 127 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND));
127 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); 128 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
128 AddChildView(find_text_); 129 AddChildView(find_text_);
129 130
130 find_previous_button_->SetIcon(kCaretUpIcon);
131 find_next_button_->SetIcon(kCaretDownIcon);
132 close_button_->SetIcon(ui::kCloseIcon);
133
134 find_previous_button_->set_id(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON); 131 find_previous_button_->set_id(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON);
135 find_previous_button_->SetFocusForPlatform(); 132 find_previous_button_->SetFocusForPlatform();
136 find_previous_button_->SetTooltipText( 133 find_previous_button_->SetTooltipText(
137 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); 134 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP));
138 find_previous_button_->SetAccessibleName( 135 find_previous_button_->SetAccessibleName(
139 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); 136 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS));
140 AddChildView(find_previous_button_); 137 AddChildView(find_previous_button_);
141 138
142 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); 139 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON);
143 find_next_button_->SetFocusForPlatform(); 140 find_next_button_->SetFocusForPlatform();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // FindBarView, DropdownBarHostDelegate implementation: 270 // FindBarView, DropdownBarHostDelegate implementation:
274 271
275 void FindBarView::SetFocusAndSelection(bool select_all) { 272 void FindBarView::SetFocusAndSelection(bool select_all) {
276 find_text_->RequestFocus(); 273 find_text_->RequestFocus();
277 GetWidget()->GetInputMethod()->ShowImeIfNeeded(); 274 GetWidget()->GetInputMethod()->ShowImeIfNeeded();
278 if (select_all && !find_text_->text().empty()) 275 if (select_all && !find_text_->text().empty())
279 find_text_->SelectAll(true); 276 find_text_->SelectAll(true);
280 } 277 }
281 278
282 //////////////////////////////////////////////////////////////////////////////// 279 ////////////////////////////////////////////////////////////////////////////////
283 // FindBarView, views::VectorIconButtonDelegate implementation: 280 // FindBarView, views::ButtonListener implementation:
284 281
285 void FindBarView::ButtonPressed( 282 void FindBarView::ButtonPressed(
286 views::Button* sender, const ui::Event& event) { 283 views::Button* sender, const ui::Event& event) {
287 switch (sender->id()) { 284 switch (sender->id()) {
288 case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON: 285 case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON:
289 case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON: 286 case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON:
290 if (!find_text_->text().empty()) { 287 if (!find_text_->text().empty()) {
291 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( 288 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(
292 find_bar_host_->GetFindBarController()->web_contents()); 289 find_bar_host_->GetFindBarController()->web_contents());
293 find_tab_helper->StartFinding( 290 find_tab_helper->StartFinding(
294 find_text_->text(), 291 find_text_->text(),
295 sender->id() == VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON, 292 sender->id() == VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON,
296 false); // Not case sensitive. 293 false); // Not case sensitive.
297 } 294 }
298 break; 295 break;
299 case VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON: 296 case VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON:
300 find_bar_host_->GetFindBarController()->EndFindSession( 297 find_bar_host_->GetFindBarController()->EndFindSession(
301 FindBarController::kKeepSelectionOnPage, 298 FindBarController::kKeepSelectionOnPage,
302 FindBarController::kKeepResultsInFindBox); 299 FindBarController::kKeepResultsInFindBox);
303 break; 300 break;
304 default: 301 default:
305 NOTREACHED() << "Unknown button"; 302 NOTREACHED() << "Unknown button";
306 break; 303 break;
307 } 304 }
308 } 305 }
309 306
310 SkColor FindBarView::GetVectorIconBaseColor() const {
311 return GetNativeTheme()->GetSystemColor(
312 ui::NativeTheme::kColorId_TextfieldDefaultColor);
313 }
314
315 //////////////////////////////////////////////////////////////////////////////// 307 ////////////////////////////////////////////////////////////////////////////////
316 // FindBarView, views::TextfieldController implementation: 308 // FindBarView, views::TextfieldController implementation:
317 309
318 bool FindBarView::HandleKeyEvent(views::Textfield* sender, 310 bool FindBarView::HandleKeyEvent(views::Textfield* sender,
319 const ui::KeyEvent& key_event) { 311 const ui::KeyEvent& key_event) {
320 // If the dialog is not visible, there is no reason to process keyboard input. 312 // If the dialog is not visible, there is no reason to process keyboard input.
321 if (!find_bar_host_->IsVisible()) 313 if (!find_bar_host_->IsVisible())
322 return false; 314 return false;
323 315
324 if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event)) 316 if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event))
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, 407 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW,
416 bg_color); 408 bg_color);
417 set_background(new views::BubbleBackground(border.get())); 409 set_background(new views::BubbleBackground(border.get()));
418 SetBorder(std::move(border)); 410 SetBorder(std::move(border));
419 411
420 match_count_text_->SetBackgroundColor(bg_color); 412 match_count_text_->SetBackgroundColor(bg_color);
421 SkColor text_color = 413 SkColor text_color =
422 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); 414 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor);
423 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); 415 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69));
424 separator_->SetColor(SkColorSetA(text_color, 0x26)); 416 separator_->SetColor(SkColorSetA(text_color, 0x26));
417
418 const SkColor base_icon_color = GetNativeTheme()->GetSystemColor(
419 ui::NativeTheme::kColorId_TextfieldDefaultColor);
420 views::SetImageFromVectorIcon(find_previous_button_, kCaretUpIcon,
421 base_icon_color);
422 views::SetImageFromVectorIcon(find_next_button_, kCaretDownIcon,
423 base_icon_color);
424 views::SetImageFromVectorIcon(close_button_, ui::kCloseIcon, base_icon_color);
425 } 425 }
426
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698