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

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

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: check details 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_factory.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_(views::CreateVectorImageButton(this)),
121 find_next_button_(new views::VectorIconButton(this)), 121 find_next_button_(views::CreateVectorImageButton(this)),
122 close_button_(new views::VectorIconButton(this)) { 122 close_button_(views::CreateVectorImageButton(this)) {
123 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); 123 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
124 find_text_->set_default_width_in_chars(kDefaultCharWidth); 124 find_text_->set_default_width_in_chars(kDefaultCharWidth);
125 find_text_->set_controller(this); 125 find_text_->set_controller(this);
126 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); 126 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND));
127 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); 127 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
128 AddChildView(find_text_); 128 AddChildView(find_text_);
129 129
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); 130 find_previous_button_->set_id(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON);
135 find_previous_button_->SetFocusForPlatform(); 131 find_previous_button_->SetFocusForPlatform();
136 find_previous_button_->SetTooltipText( 132 find_previous_button_->SetTooltipText(
137 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); 133 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP));
138 find_previous_button_->SetAccessibleName( 134 find_previous_button_->SetAccessibleName(
139 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); 135 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS));
140 AddChildView(find_previous_button_); 136 AddChildView(find_previous_button_);
141 137
142 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); 138 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON);
143 find_next_button_->SetFocusForPlatform(); 139 find_next_button_->SetFocusForPlatform();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // FindBarView, DropdownBarHostDelegate implementation: 269 // FindBarView, DropdownBarHostDelegate implementation:
274 270
275 void FindBarView::SetFocusAndSelection(bool select_all) { 271 void FindBarView::SetFocusAndSelection(bool select_all) {
276 find_text_->RequestFocus(); 272 find_text_->RequestFocus();
277 GetWidget()->GetInputMethod()->ShowImeIfNeeded(); 273 GetWidget()->GetInputMethod()->ShowImeIfNeeded();
278 if (select_all && !find_text_->text().empty()) 274 if (select_all && !find_text_->text().empty())
279 find_text_->SelectAll(true); 275 find_text_->SelectAll(true);
280 } 276 }
281 277
282 //////////////////////////////////////////////////////////////////////////////// 278 ////////////////////////////////////////////////////////////////////////////////
283 // FindBarView, views::VectorIconButtonDelegate implementation: 279 // FindBarView, views::ButtonListener implementation:
284 280
285 void FindBarView::ButtonPressed( 281 void FindBarView::ButtonPressed(
286 views::Button* sender, const ui::Event& event) { 282 views::Button* sender, const ui::Event& event) {
287 switch (sender->id()) { 283 switch (sender->id()) {
288 case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON: 284 case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON:
289 case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON: 285 case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON:
290 if (!find_text_->text().empty()) { 286 if (!find_text_->text().empty()) {
291 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( 287 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(
292 find_bar_host_->GetFindBarController()->web_contents()); 288 find_bar_host_->GetFindBarController()->web_contents());
293 find_tab_helper->StartFinding( 289 find_tab_helper->StartFinding(
294 find_text_->text(), 290 find_text_->text(),
295 sender->id() == VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON, 291 sender->id() == VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON,
296 false); // Not case sensitive. 292 false); // Not case sensitive.
297 } 293 }
298 break; 294 break;
299 case VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON: 295 case VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON:
300 find_bar_host_->GetFindBarController()->EndFindSession( 296 find_bar_host_->GetFindBarController()->EndFindSession(
301 FindBarController::kKeepSelectionOnPage, 297 FindBarController::kKeepSelectionOnPage,
302 FindBarController::kKeepResultsInFindBox); 298 FindBarController::kKeepResultsInFindBox);
303 break; 299 break;
304 default: 300 default:
305 NOTREACHED() << "Unknown button"; 301 NOTREACHED() << "Unknown button";
306 break; 302 break;
307 } 303 }
308 } 304 }
309 305
310 SkColor FindBarView::GetVectorIconBaseColor() const {
311 return GetNativeTheme()->GetSystemColor(
312 ui::NativeTheme::kColorId_TextfieldDefaultColor);
313 }
314
315 //////////////////////////////////////////////////////////////////////////////// 306 ////////////////////////////////////////////////////////////////////////////////
316 // FindBarView, views::TextfieldController implementation: 307 // FindBarView, views::TextfieldController implementation:
317 308
318 bool FindBarView::HandleKeyEvent(views::Textfield* sender, 309 bool FindBarView::HandleKeyEvent(views::Textfield* sender,
319 const ui::KeyEvent& key_event) { 310 const ui::KeyEvent& key_event) {
320 // If the dialog is not visible, there is no reason to process keyboard input. 311 // If the dialog is not visible, there is no reason to process keyboard input.
321 if (!find_bar_host_->IsVisible()) 312 if (!find_bar_host_->IsVisible())
322 return false; 313 return false;
323 314
324 if (find_bar_host_->MaybeForwardKeyEventToWebpage(key_event)) 315 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, 406 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW,
416 bg_color); 407 bg_color);
417 set_background(new views::BubbleBackground(border.get())); 408 set_background(new views::BubbleBackground(border.get()));
418 SetBorder(std::move(border)); 409 SetBorder(std::move(border));
419 410
420 match_count_text_->SetBackgroundColor(bg_color); 411 match_count_text_->SetBackgroundColor(bg_color);
421 SkColor text_color = 412 SkColor text_color =
422 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); 413 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor);
423 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); 414 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69));
424 separator_->SetColor(SkColorSetA(text_color, 0x26)); 415 separator_->SetColor(SkColorSetA(text_color, 0x26));
416
417 const SkColor base_icon_color = GetNativeTheme()->GetSystemColor(
418 ui::NativeTheme::kColorId_TextfieldDefaultColor);
419 views::SetImageFromVectorIcon(find_previous_button_, kCaretUpIcon,
420 base_icon_color);
421 views::SetImageFromVectorIcon(find_next_button_, kCaretDownIcon,
422 base_icon_color);
423 views::SetImageFromVectorIcon(close_button_, ui::kCloseIcon, base_icon_color);
425 } 424 }
426
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/find_bar_view.h ('k') | chrome/browser/ui/views/infobars/infobar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698