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

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

Issue 1270783005: V1 of material design find in page bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mvp Created 5 years, 4 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/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/themes/theme_properties.h" 13 #include "chrome/browser/themes/theme_properties.h"
14 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 14 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
15 #include "chrome/browser/ui/find_bar/find_bar_state.h" 15 #include "chrome/browser/ui/find_bar/find_bar_state.h"
16 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h" 16 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h"
17 #include "chrome/browser/ui/find_bar/find_notification_details.h" 17 #include "chrome/browser/ui/find_bar/find_notification_details.h"
18 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 18 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
19 #include "chrome/browser/ui/view_ids.h" 19 #include "chrome/browser/ui/view_ids.h"
20 #include "chrome/browser/ui/views/find_bar_host.h" 20 #include "chrome/browser/ui/views/find_bar_host.h"
21 #include "chrome/browser/ui/views/frame/browser_view.h" 21 #include "chrome/browser/ui/views/frame/browser_view.h"
22 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
23 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
24 #include "third_party/skia/include/core/SkPaint.h" 24 #include "third_party/skia/include/core/SkPaint.h"
25 #include "ui/base/ime/input_method.h" 25 #include "ui/base/ime/input_method.h"
26 #include "ui/base/ime/text_input_flags.h" 26 #include "ui/base/ime/text_input_flags.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/material_design/material_design_controller.h"
28 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/base/theme_provider.h" 30 #include "ui/base/theme_provider.h"
30 #include "ui/events/event.h" 31 #include "ui/events/event.h"
31 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/paint_vector_icon.h"
34 #include "ui/gfx/vector_icons_public2.h"
35 #include "ui/native_theme/common_theme.h"
36 #include "ui/native_theme/native_theme.h"
32 #include "ui/resources/grit/ui_resources.h" 37 #include "ui/resources/grit/ui_resources.h"
38 #include "ui/views/background.h"
33 #include "ui/views/border.h" 39 #include "ui/views/border.h"
40 #include "ui/views/bubble/bubble_border.h"
34 #include "ui/views/controls/button/image_button.h" 41 #include "ui/views/controls/button/image_button.h"
35 #include "ui/views/controls/label.h" 42 #include "ui/views/controls/label.h"
43 #include "ui/views/controls/separator.h"
44 #include "ui/views/layout/box_layout.h"
36 #include "ui/views/painter.h" 45 #include "ui/views/painter.h"
37 #include "ui/views/widget/widget.h" 46 #include "ui/views/widget/widget.h"
38 47
39 namespace { 48 namespace {
40 49
41 // The margins around the UI controls, derived from assets and design specs. 50 // The margins around the UI controls, derived from assets and design specs.
42 const int kMarginLeftOfCloseButton = 3; 51 const int kMarginLeftOfCloseButton = 3;
43 const int kMarginRightOfCloseButton = 7; 52 const int kMarginRightOfCloseButton = 7;
44 const int kMarginLeftOfMatchCountLabel = 3; 53 const int kMarginLeftOfMatchCountLabel = 3;
45 const int kMarginRightOfMatchCountLabel = 1; 54 const int kMarginRightOfMatchCountLabel = 1;
(...skipping 16 matching lines...) Expand all
62 // The background color of the match count label when results are found. 71 // The background color of the match count label when results are found.
63 const SkColor kBackgroundColorMatch = SkColorSetARGB(0, 255, 255, 255); 72 const SkColor kBackgroundColorMatch = SkColorSetARGB(0, 255, 255, 255);
64 73
65 // The background color of the match count label when no results are found. 74 // The background color of the match count label when no results are found.
66 const SkColor kBackgroundColorNoMatch = SkColorSetRGB(255, 102, 102); 75 const SkColor kBackgroundColorNoMatch = SkColorSetRGB(255, 102, 102);
67 76
68 // The default number of average characters that the text box will be. This 77 // The default number of average characters that the text box will be. This
69 // number brings the width on a "regular fonts" system to about 300px. 78 // number brings the width on a "regular fonts" system to about 300px.
70 const int kDefaultCharWidth = 43; 79 const int kDefaultCharWidth = 43;
71 80
81 // Creates a label that mouse click focus to a given target.
sky 2015/08/05 00:06:01 This comment is missing a few words, and I was con
Evan Stade 2015/08/05 19:04:25 Done.
82 class MatchCountLabel : public views::Label {
sky 2015/08/05 00:06:01 Rather than this, and FocusForwarderView, could we
Evan Stade 2015/08/05 19:04:25 that sounds more difficult because a) we'd probabl
83 public:
84 explicit MatchCountLabel(views::View* target_view)
85 : target_view_(target_view) {
86 DCHECK(target_view);
87 }
88
89 // views::Label overrides:
90 bool OnMousePressed(const ui::MouseEvent& event) override {
91 target_view_->RequestFocus();
92 return true;
93 }
94
95 private:
96 views::View* target_view_;
97
98 DISALLOW_COPY_AND_ASSIGN(MatchCountLabel);
99 };
100
72 } // namespace 101 } // namespace
73 102
74 //////////////////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////////////////
75 // FindBarView, public: 104 // FindBarView, public:
76 105
77 FindBarView::FindBarView(FindBarHost* host) 106 FindBarView::FindBarView(FindBarHost* host)
78 : DropdownBarView(host), 107 : DropdownBarView(host),
79 find_text_(NULL), 108 find_text_(NULL),
80 match_count_text_(NULL), 109 match_count_text_(NULL),
81 focus_forwarder_view_(NULL), 110 focus_forwarder_view_(NULL),
82 find_previous_button_(NULL), 111 find_previous_button_(NULL),
83 find_next_button_(NULL), 112 find_next_button_(NULL),
84 close_button_(NULL) { 113 close_button_(NULL) {
85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
86
87 find_text_ = new views::Textfield; 114 find_text_ = new views::Textfield;
88 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); 115 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
89 find_text_->set_default_width_in_chars(kDefaultCharWidth); 116 find_text_->set_default_width_in_chars(kDefaultCharWidth);
90 find_text_->set_controller(this); 117 find_text_->set_controller(this);
91 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); 118 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND));
92 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); 119 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
93 // The find bar textfield has a background image instead of a border.
94 find_text_->SetBorder(views::Border::NullBorder());
95 AddChildView(find_text_); 120 AddChildView(find_text_);
96 121
97 match_count_text_ = new views::Label();
98 AddChildView(match_count_text_);
99
100 // Create a focus forwarder view which sends focus to find_text_.
101 focus_forwarder_view_ = new FocusForwarderView(find_text_);
102 AddChildView(focus_forwarder_view_);
103
104 find_previous_button_ = new views::ImageButton(this); 122 find_previous_button_ = new views::ImageButton(this);
105 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); 123 find_previous_button_->set_tag(FIND_PREVIOUS_TAG);
106 find_previous_button_->SetFocusable(true); 124 find_previous_button_->SetFocusable(true);
107 find_previous_button_->SetImage(views::CustomButton::STATE_NORMAL,
108 rb.GetImageSkiaNamed(IDR_FINDINPAGE_PREV));
109 find_previous_button_->SetImage(views::CustomButton::STATE_HOVERED,
110 rb.GetImageSkiaNamed(IDR_FINDINPAGE_PREV_H));
111 find_previous_button_->SetImage(views::CustomButton::STATE_PRESSED,
112 rb.GetImageSkiaNamed(IDR_FINDINPAGE_PREV_P));
113 find_previous_button_->SetImage(views::CustomButton::STATE_DISABLED,
114 rb.GetImageSkiaNamed(IDR_FINDINPAGE_PREV_D));
115 find_previous_button_->SetTooltipText( 125 find_previous_button_->SetTooltipText(
116 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); 126 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP));
117 find_previous_button_->SetAccessibleName( 127 find_previous_button_->SetAccessibleName(
118 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); 128 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS));
119 AddChildView(find_previous_button_); 129 AddChildView(find_previous_button_);
120 130
121 find_next_button_ = new views::ImageButton(this); 131 find_next_button_ = new views::ImageButton(this);
122 find_next_button_->set_tag(FIND_NEXT_TAG); 132 find_next_button_->set_tag(FIND_NEXT_TAG);
123 find_next_button_->SetFocusable(true); 133 find_next_button_->SetFocusable(true);
124 find_next_button_->SetImage(views::CustomButton::STATE_NORMAL,
125 rb.GetImageSkiaNamed(IDR_FINDINPAGE_NEXT));
126 find_next_button_->SetImage(views::CustomButton::STATE_HOVERED,
127 rb.GetImageSkiaNamed(IDR_FINDINPAGE_NEXT_H));
128 find_next_button_->SetImage(views::CustomButton::STATE_PRESSED,
129 rb.GetImageSkiaNamed(IDR_FINDINPAGE_NEXT_P));
130 find_next_button_->SetImage(views::CustomButton::STATE_DISABLED,
131 rb.GetImageSkiaNamed(IDR_FINDINPAGE_NEXT_D));
132 find_next_button_->SetTooltipText( 134 find_next_button_->SetTooltipText(
133 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); 135 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP));
134 find_next_button_->SetAccessibleName( 136 find_next_button_->SetAccessibleName(
135 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); 137 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT));
136 AddChildView(find_next_button_); 138 AddChildView(find_next_button_);
137 139
138 close_button_ = new views::ImageButton(this); 140 close_button_ = new views::ImageButton(this);
139 close_button_->set_tag(CLOSE_TAG); 141 close_button_->set_tag(CLOSE_TAG);
140 close_button_->SetFocusable(true); 142 close_button_->SetFocusable(true);
141 close_button_->SetImage(views::CustomButton::STATE_NORMAL,
142 rb.GetImageSkiaNamed(IDR_CLOSE_1));
143 close_button_->SetImage(views::CustomButton::STATE_HOVERED,
144 rb.GetImageSkiaNamed(IDR_CLOSE_1_H));
145 close_button_->SetImage(views::CustomButton::STATE_PRESSED,
146 rb.GetImageSkiaNamed(IDR_CLOSE_1_P));
147 close_button_->SetTooltipText( 143 close_button_->SetTooltipText(
148 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); 144 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP));
149 close_button_->SetAccessibleName( 145 close_button_->SetAccessibleName(
150 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); 146 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
151 close_button_->SetAnimationDuration(0); 147 close_button_->SetAnimationDuration(0);
152 AddChildView(close_button_); 148 AddChildView(close_button_);
153 149
154 SetBackground(rb.GetImageSkiaNamed(IDR_FIND_DLG_LEFT_BACKGROUND), 150 EnableCanvasFlippingForRTLUI(true);
155 rb.GetImageSkiaNamed(IDR_FIND_DLG_RIGHT_BACKGROUND));
156 151
157 SetBorderFromIds( 152 if (ui::MaterialDesignController::IsModeMaterial())
158 IDR_FIND_DIALOG_LEFT, IDR_FIND_DIALOG_MIDDLE, IDR_FIND_DIALOG_RIGHT); 153 InitViewsForMaterial();
159 154 else
160 preferred_height_ = rb.GetImageSkiaNamed(IDR_FIND_DIALOG_MIDDLE)->height(); 155 InitViewsForNonMaterial();
161
162 static const int kImages[] = IMAGE_GRID(IDR_TEXTFIELD);
163 find_text_border_.reset(views::Painter::CreateImageGridPainter(kImages));
164
165 EnableCanvasFlippingForRTLUI(true);
166 } 156 }
167 157
168 FindBarView::~FindBarView() { 158 FindBarView::~FindBarView() {
169 } 159 }
170 160
171 void FindBarView::SetFindTextAndSelectedRange( 161 void FindBarView::SetFindTextAndSelectedRange(
172 const base::string16& find_text, 162 const base::string16& find_text,
173 const gfx::Range& selected_range) { 163 const gfx::Range& selected_range) {
174 find_text_->SetText(find_text); 164 find_text_->SetText(find_text);
175 find_text_->SelectRange(selected_range); 165 find_text_->SelectRange(selected_range);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 find_text_->RequestFocus(); 226 find_text_->RequestFocus();
237 GetWidget()->GetInputMethod()->ShowImeIfNeeded(); 227 GetWidget()->GetInputMethod()->ShowImeIfNeeded();
238 if (select_all && !find_text_->text().empty()) 228 if (select_all && !find_text_->text().empty())
239 find_text_->SelectAll(true); 229 find_text_->SelectAll(true);
240 } 230 }
241 231
242 /////////////////////////////////////////////////////////////////////////////// 232 ///////////////////////////////////////////////////////////////////////////////
243 // FindBarView, views::View overrides: 233 // FindBarView, views::View overrides:
244 234
245 void FindBarView::OnPaint(gfx::Canvas* canvas) { 235 void FindBarView::OnPaint(gfx::Canvas* canvas) {
236 if (ui::MaterialDesignController::IsModeMaterial())
237 return views::View::OnPaint(canvas);
238
246 // Paint drop down bar border and background. 239 // Paint drop down bar border and background.
247 DropdownBarView::OnPaint(canvas); 240 DropdownBarView::OnPaint(canvas);
248 241
249 // Paint the background and border for the textfield. 242 // Paint the background and border for the textfield.
250 const int find_text_x = kMarginLeftOfFindTextfield / 2; 243 const int find_text_x = kMarginLeftOfFindTextfield / 2;
251 const gfx::Rect text_bounds(find_text_x, find_next_button_->y(), 244 const gfx::Rect text_bounds(find_text_x, find_next_button_->y(),
252 find_next_button_->bounds().right() - find_text_x, 245 find_next_button_->bounds().right() - find_text_x,
253 find_next_button_->height()); 246 find_next_button_->height());
254 const int kBorderCornerRadius = 2; 247 const int kBorderCornerRadius = 2;
255 gfx::Rect background_bounds = text_bounds; 248 gfx::Rect background_bounds = text_bounds;
(...skipping 15 matching lines...) Expand all
271 // subtract 3 for top and 3 for bottom. 264 // subtract 3 for top and 3 for bottom.
272 gfx::Rect match_count_background_bounds(match_count_text_->bounds()); 265 gfx::Rect match_count_background_bounds(match_count_text_->bounds());
273 match_count_background_bounds.set_height( 266 match_count_background_bounds.set_height(
274 find_previous_button_->height() - 6); // Subtract 3px x 2. 267 find_previous_button_->height() - 6); // Subtract 3px x 2.
275 match_count_background_bounds.set_y( 268 match_count_background_bounds.set_y(
276 (height() - match_count_background_bounds.height()) / 2); 269 (height() - match_count_background_bounds.height()) / 2);
277 canvas->FillRect(match_count_background_bounds, 270 canvas->FillRect(match_count_background_bounds,
278 match_count_text_->background_color()); 271 match_count_text_->background_color());
279 } 272 }
280 273
274 void FindBarView::OnPaintBackground(gfx::Canvas* canvas) {
275 if (!ui::MaterialDesignController::IsModeMaterial())
276 return views::View::OnPaintBackground(canvas);
277
278 // Draw within the lines.
279 canvas->Save();
280 gfx::Rect bounds = GetLocalBounds();
281 bounds.Inset(border()->GetInsets());
282 canvas->ClipRect(bounds);
283 views::View::OnPaintBackground(canvas);
284 canvas->Restore();
285 }
286
281 void FindBarView::Layout() { 287 void FindBarView::Layout() {
288 if (ui::MaterialDesignController::IsModeMaterial())
289 return views::View::Layout();
290
282 int panel_width = GetPreferredSize().width(); 291 int panel_width = GetPreferredSize().width();
283 292
284 // Stay within view bounds. 293 // Stay within view bounds.
285 int view_width = width(); 294 int view_width = width();
286 if (view_width && view_width < panel_width) 295 if (view_width && view_width < panel_width)
287 panel_width = view_width; 296 panel_width = view_width;
288 297
289 // First we draw the close button on the far right. 298 // First we draw the close button on the far right.
290 gfx::Size sz = close_button_->GetPreferredSize(); 299 gfx::Size sz = close_button_->GetPreferredSize();
291 close_button_->SetBounds(panel_width - sz.width() - 300 close_button_->SetBounds(panel_width - sz.width() -
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // between the find text box and the find button so that when the user clicks 349 // between the find text box and the find button so that when the user clicks
341 // in that area we focus on the find text box. 350 // in that area we focus on the find text box.
342 const int find_text_edge = find_text_->x() + find_text_->width(); 351 const int find_text_edge = find_text_->x() + find_text_->width();
343 focus_forwarder_view_->SetBounds( 352 focus_forwarder_view_->SetBounds(
344 find_text_edge, find_previous_button_->y(), 353 find_text_edge, find_previous_button_->y(),
345 find_previous_button_->x() - find_text_edge, 354 find_previous_button_->x() - find_text_edge,
346 find_previous_button_->height()); 355 find_previous_button_->height());
347 } 356 }
348 357
349 gfx::Size FindBarView::GetPreferredSize() const { 358 gfx::Size FindBarView::GetPreferredSize() const {
359 if (ui::MaterialDesignController::IsModeMaterial()) {
360 gfx::Size size = views::View::GetPreferredSize();
361 size.set_width(find_text_->GetPreferredSize().width());
sky 2015/08/05 00:06:01 It's worth a comment as to why the preferred size
Evan Stade 2015/08/05 19:04:25 Done.
362 return size;
363 }
364
350 gfx::Size prefsize = find_text_->GetPreferredSize(); 365 gfx::Size prefsize = find_text_->GetPreferredSize();
351 prefsize.set_height(preferred_height_); 366 prefsize.set_height(preferred_height_);
352 367
353 // Add up all the preferred sizes and margins of the rest of the controls. 368 // Add up all the preferred sizes and margins of the rest of the controls.
354 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + 369 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton +
355 kMarginLeftOfFindTextfield - 370 kMarginLeftOfFindTextfield -
356 find_text_->GetInsets().width(), 371 find_text_->GetInsets().width(),
357 0); 372 0);
358 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); 373 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0);
359 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); 374 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 Find(sender->text()); 448 Find(sender->text());
434 } 449 }
435 450
436 void FindBarView::OnAfterPaste() { 451 void FindBarView::OnAfterPaste() {
437 // Clear the last search text so we always search for the user input after 452 // Clear the last search text so we always search for the user input after
438 // a paste operation, even if the pasted text is the same as before. 453 // a paste operation, even if the pasted text is the same as before.
439 // See http://crbug.com/79002 454 // See http://crbug.com/79002
440 last_searched_text_.clear(); 455 last_searched_text_.clear();
441 } 456 }
442 457
458 void FindBarView::InitViewsForNonMaterial() {
459 match_count_text_ = new views::Label();
460 AddChildView(match_count_text_);
461
462 // Create a focus forwarder view which sends focus to find_text_.
463 focus_forwarder_view_ = new FocusForwarderView(find_text_);
464 AddChildView(focus_forwarder_view_);
465
466 // The find bar textfield has a background image instead of a border.
467 find_text_->SetBorder(views::Border::NullBorder());
468
469 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
470 find_previous_button_->SetImage(views::CustomButton::STATE_NORMAL,
471 rb.GetImageSkiaNamed(IDR_FINDINPAGE_PREV));
472 find_previous_button_->SetImage(views::CustomButton::STATE_HOVERED,
473 rb.GetImageSkiaNamed(IDR_FINDINPAGE_PREV_H));
474 find_previous_button_->SetImage(views::CustomButton::STATE_PRESSED,
475 rb.GetImageSkiaNamed(IDR_FINDINPAGE_PREV_P));
476 find_previous_button_->SetImage(views::CustomButton::STATE_DISABLED,
477 rb.GetImageSkiaNamed(IDR_FINDINPAGE_PREV_D));
478
479 find_next_button_->SetImage(views::CustomButton::STATE_NORMAL,
480 rb.GetImageSkiaNamed(IDR_FINDINPAGE_NEXT));
481 find_next_button_->SetImage(views::CustomButton::STATE_HOVERED,
482 rb.GetImageSkiaNamed(IDR_FINDINPAGE_NEXT_H));
483 find_next_button_->SetImage(views::CustomButton::STATE_PRESSED,
484 rb.GetImageSkiaNamed(IDR_FINDINPAGE_NEXT_P));
485 find_next_button_->SetImage(views::CustomButton::STATE_DISABLED,
486 rb.GetImageSkiaNamed(IDR_FINDINPAGE_NEXT_D));
487
488 close_button_->SetImage(views::CustomButton::STATE_NORMAL,
489 rb.GetImageSkiaNamed(IDR_CLOSE_1));
490 close_button_->SetImage(views::CustomButton::STATE_HOVERED,
491 rb.GetImageSkiaNamed(IDR_CLOSE_1_H));
492 close_button_->SetImage(views::CustomButton::STATE_PRESSED,
493 rb.GetImageSkiaNamed(IDR_CLOSE_1_P));
494
495 SetBackground(rb.GetImageSkiaNamed(IDR_FIND_DLG_LEFT_BACKGROUND),
496 rb.GetImageSkiaNamed(IDR_FIND_DLG_RIGHT_BACKGROUND));
497 SetBorderFromIds(IDR_FIND_DIALOG_LEFT, IDR_FIND_DIALOG_MIDDLE,
498 IDR_FIND_DIALOG_RIGHT);
499
500 preferred_height_ = rb.GetImageSkiaNamed(IDR_FIND_DIALOG_MIDDLE)->height();
501
502 static const int kImages[] = IMAGE_GRID(IDR_TEXTFIELD);
503 find_text_border_.reset(views::Painter::CreateImageGridPainter(kImages));
504 }
505
506 void FindBarView::InitViewsForMaterial() {
507 // The background color is not used since there's no arrow.
508 // TODO(estade): this shadow is not quite the same as in the mocks.
509 SetBorder(make_scoped_ptr(new views::BubbleBorder(
510 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW,
511 SK_ColorGREEN)));
512
513 match_count_text_ = new MatchCountLabel(find_text_);
514 AddChildViewAt(match_count_text_, 1);
515
516 views::Separator* separator =
517 new views::Separator(views::Separator::VERTICAL);
518 // TODO(estade): refine these constants.
519 separator->SetColor(SkColorSetRGB(0xD5, 0xD5, 0xD5));
520 separator->SetBorder(views::Border::CreateEmptyBorder(4, 10, 4, 10));
521 AddChildViewAt(separator, 2);
522
523 find_text_->SetBorder(views::Border::NullBorder());
524 // Reserve horizontal space. Note that |find_text_| will only be allotted
525 // what space remains after other elements have been laid out, but this
526 // setting is still used when calculating the overall find bar's width.
527 find_text_->set_default_width_in_chars(30);
528
529 struct {
530 views::ImageButton* button;
531 gfx::VectorIconId id;
532 } button_images[] = {
533 {find_previous_button_, gfx::VectorIconId::FIND_PREV},
534 {find_next_button_, gfx::VectorIconId::FIND_NEXT},
535 {close_button_, gfx::VectorIconId::FIND_CLOSE},
536 };
537
538 SkColor grey;
539 ui::CommonThemeGetSystemColor(ui::NativeTheme::kColorId_ChromeIconGrey,
540 &grey);
541 SkColor blue;
542 ui::CommonThemeGetSystemColor(ui::NativeTheme::kColorId_GoogleBlue, &blue);
543 for (size_t i = 0; i < arraysize(button_images); ++i) {
544 views::ImageButton* button = button_images[i].button;
545 button->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
546 views::ImageButton::ALIGN_MIDDLE);
547
548 gfx::ImageSkia image = gfx::CreateVectorIcon(button_images[i].id, 16, grey);
549 button->SetImage(views::CustomButton::STATE_NORMAL, &image);
550 image = gfx::CreateVectorIcon(button_images[i].id, 16, blue);
551 button->SetImage(views::CustomButton::STATE_PRESSED, &image);
552 // TODO(estade): I don't think the buttons are ever disabled, so this image
553 // is never visible. Consider removing this image or setting the buttons to
554 // disabled at sensible times.
555 image = gfx::CreateVectorIcon(button_images[i].id, 16,
556 SkColorSetA(grey, 0xff / 2));
557 button->SetImage(views::CustomButton::STATE_DISABLED, &image);
558 }
559
560 views::BoxLayout* manager =
561 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
562 SetLayoutManager(manager);
563 manager->SetFlexForView(find_text_, 1);
564 }
565
443 void FindBarView::Find(const base::string16& search_text) { 566 void FindBarView::Find(const base::string16& search_text) {
444 FindBarController* controller = find_bar_host()->GetFindBarController(); 567 FindBarController* controller = find_bar_host()->GetFindBarController();
445 DCHECK(controller); 568 DCHECK(controller);
446 content::WebContents* web_contents = controller->web_contents(); 569 content::WebContents* web_contents = controller->web_contents();
447 // We must guard against a NULL web_contents, which can happen if the text 570 // We must guard against a NULL web_contents, which can happen if the text
448 // in the Find box is changed right after the tab is destroyed. Otherwise, it 571 // in the Find box is changed right after the tab is destroyed. Otherwise, it
449 // can lead to crashes, as exposed by automation testing in issue 8048. 572 // can lead to crashes, as exposed by automation testing in issue 8048.
450 if (!web_contents) 573 if (!web_contents)
451 return; 574 return;
452 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); 575 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 618
496 FindBarHost* FindBarView::find_bar_host() const { 619 FindBarHost* FindBarView::find_bar_host() const {
497 return static_cast<FindBarHost*>(host()); 620 return static_cast<FindBarHost*>(host());
498 } 621 }
499 622
500 const char* FindBarView::GetClassName() const { 623 const char* FindBarView::GetClassName() const {
501 return "FindBarView"; 624 return "FindBarView";
502 } 625 }
503 626
504 void FindBarView::OnThemeChanged() { 627 void FindBarView::OnThemeChanged() {
628 if (ui::MaterialDesignController::IsModeMaterial())
629 return;
630
505 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 631 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
506 if (GetThemeProvider()) { 632 if (GetThemeProvider()) {
507 close_button_->SetBackground( 633 close_button_->SetBackground(
508 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), 634 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT),
509 rb.GetImageSkiaNamed(IDR_CLOSE_1), 635 rb.GetImageSkiaNamed(IDR_CLOSE_1),
510 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); 636 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK));
511 } 637 }
512 } 638 }
639
640 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
641 if (!ui::MaterialDesignController::IsModeMaterial())
642 return;
643
644 SkColor color =
645 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground);
646 set_background(views::Background::CreateSolidBackground(color));
647 match_count_text_->SetBackgroundColor(color);
648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698