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

Side by Side Diff: ui/app_list/views/search_box_view.cc

Issue 894203004: Add a proper shadow to the experimental app list search box. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@make_doodle_clickable
Patch Set: address_comments Created 5 years, 10 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
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/app_list/views/search_box_view.h" 5 #include "ui/app_list/views/search_box_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/app_list/app_list_constants.h" 9 #include "ui/app_list/app_list_constants.h"
10 #include "ui/app_list/app_list_model.h" 10 #include "ui/app_list/app_list_model.h"
11 #include "ui/app_list/app_list_switches.h" 11 #include "ui/app_list/app_list_switches.h"
12 #include "ui/app_list/app_list_view_delegate.h" 12 #include "ui/app_list/app_list_view_delegate.h"
13 #include "ui/app_list/search_box_model.h" 13 #include "ui/app_list/search_box_model.h"
14 #include "ui/app_list/speech_ui_model.h" 14 #include "ui/app_list/speech_ui_model.h"
15 #include "ui/app_list/views/app_list_menu_views.h" 15 #include "ui/app_list/views/app_list_menu_views.h"
16 #include "ui/app_list/views/search_box_view_delegate.h" 16 #include "ui/app_list/views/search_box_view_delegate.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/events/event.h" 18 #include "ui/events/event.h"
19 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
20 #include "ui/resources/grit/ui_resources.h" 20 #include "ui/resources/grit/ui_resources.h"
21 #include "ui/views/border.h" 21 #include "ui/views/border.h"
22 #include "ui/views/controls/button/image_button.h" 22 #include "ui/views/controls/button/image_button.h"
23 #include "ui/views/controls/button/menu_button.h" 23 #include "ui/views/controls/button/menu_button.h"
24 #include "ui/views/controls/image_view.h" 24 #include "ui/views/controls/image_view.h"
25 #include "ui/views/controls/textfield/textfield.h" 25 #include "ui/views/controls/textfield/textfield.h"
26 #include "ui/views/layout/box_layout.h" 26 #include "ui/views/layout/box_layout.h"
27 #include "ui/views/layout/fill_layout.h"
28 #include "ui/views/shadow_border.h"
27 29
28 namespace app_list { 30 namespace app_list {
29 31
30 namespace { 32 namespace {
31 33
32 const int kPadding = 14; 34 const int kPadding = 14;
33 const int kPreferredWidth = 360; 35 const int kPreferredWidth = 360;
34 const int kPreferredHeight = 48; 36 const int kPreferredHeight = 48;
35 37
36 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); 38 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0);
37 39
38 // Menu offset relative to the bottom-right corner of the menu button. 40 // Menu offset relative to the bottom-right corner of the menu button.
39 const int kMenuYOffsetFromButton = -4; 41 const int kMenuYOffsetFromButton = -4;
40 const int kMenuXOffsetFromButton = -7; 42 const int kMenuXOffsetFromButton = -7;
41 43
42 const int kBackgroundBorderWidth = 1;
43 const int kBackgroundBorderBottomWidth = 1;
44 const int kBackgroundBorderCornerRadius = 2; 44 const int kBackgroundBorderCornerRadius = 2;
45 const SkColor kBackgroundBorderColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); 45
46 const SkColor kBackgroundBorderBottomColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); 46 const int kShadowBlur = 4;
47 const int kShadowYOffset = 2;
48 const SkColor kShadowColor = SkColorSetARGB(0x33, 0, 0, 0);
47 49
48 // A background that paints a solid white rounded rect with a thin grey border. 50 // A background that paints a solid white rounded rect with a thin grey border.
49 class ExperimentalSearchBoxBackground : public views::Background { 51 class ExperimentalSearchBoxBackground : public views::Background {
50 public: 52 public:
51 ExperimentalSearchBoxBackground() {} 53 ExperimentalSearchBoxBackground() {}
52 ~ExperimentalSearchBoxBackground() override {} 54 ~ExperimentalSearchBoxBackground() override {}
53 55
54 private: 56 private:
55 // views::Background overrides: 57 // views::Background overrides:
56 void Paint(gfx::Canvas* canvas, views::View* view) const override { 58 void Paint(gfx::Canvas* canvas, views::View* view) const override {
57 gfx::Rect bounds = view->GetContentsBounds(); 59 gfx::Rect bounds = view->GetContentsBounds();
58 60
59 SkPaint paint; 61 SkPaint paint;
60 paint.setFlags(SkPaint::kAntiAlias_Flag); 62 paint.setFlags(SkPaint::kAntiAlias_Flag);
61 paint.setColor(kBackgroundBorderColor);
62 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint);
63 bounds.Inset(kBackgroundBorderWidth,
64 kBackgroundBorderWidth,
65 kBackgroundBorderWidth,
66 0);
67 paint.setColor(kBackgroundBorderBottomColor);
68 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint);
69 bounds.Inset(0, 0, 0, kBackgroundBorderBottomWidth);
70 paint.setColor(kSearchBoxBackground); 63 paint.setColor(kSearchBoxBackground);
71 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint); 64 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint);
72 } 65 }
73 66
74 DISALLOW_COPY_AND_ASSIGN(ExperimentalSearchBoxBackground); 67 DISALLOW_COPY_AND_ASSIGN(ExperimentalSearchBoxBackground);
75 }; 68 };
76 69
77 } // namespace 70 } // namespace
78 71
79 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, 72 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
80 AppListViewDelegate* view_delegate) 73 AppListViewDelegate* view_delegate)
81 : delegate_(delegate), 74 : delegate_(delegate),
82 view_delegate_(view_delegate), 75 view_delegate_(view_delegate),
83 model_(NULL), 76 model_(NULL),
77 content_container_(new views::View),
84 icon_view_(NULL), 78 icon_view_(NULL),
85 back_button_(NULL), 79 back_button_(NULL),
86 speech_button_(NULL), 80 speech_button_(NULL),
87 menu_button_(NULL), 81 menu_button_(NULL),
88 search_box_(new views::Textfield), 82 search_box_(new views::Textfield),
89 contents_view_(NULL) { 83 contents_view_(NULL) {
84 SetLayoutManager(new views::FillLayout);
85 AddChildView(content_container_);
86
90 if (switches::IsExperimentalAppListEnabled()) { 87 if (switches::IsExperimentalAppListEnabled()) {
88 SetBorder(make_scoped_ptr(
89 new views::ShadowBorder(kShadowBlur, kShadowColor, kShadowYOffset, 0)));
91 back_button_ = new views::ImageButton(this); 90 back_button_ = new views::ImageButton(this);
92 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 91 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
93 back_button_->SetImage( 92 back_button_->SetImage(
94 views::ImageButton::STATE_NORMAL, 93 views::ImageButton::STATE_NORMAL,
95 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); 94 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL));
96 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, 95 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
97 views::ImageButton::ALIGN_MIDDLE); 96 views::ImageButton::ALIGN_MIDDLE);
98 AddChildView(back_button_); 97 content_container_->AddChildView(back_button_);
99 98
100 set_background(new ExperimentalSearchBoxBackground()); 99 content_container_->set_background(new ExperimentalSearchBoxBackground());
101 } else { 100 } else {
102 set_background( 101 set_background(
103 views::Background::CreateSolidBackground(kSearchBoxBackground)); 102 views::Background::CreateSolidBackground(kSearchBoxBackground));
104 SetBorder( 103 SetBorder(
105 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kTopSeparatorColor)); 104 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kTopSeparatorColor));
106 icon_view_ = new views::ImageView; 105 icon_view_ = new views::ImageView;
107 AddChildView(icon_view_); 106 content_container_->AddChildView(icon_view_);
108 } 107 }
109 108
110 views::BoxLayout* layout = 109 views::BoxLayout* layout =
111 new views::BoxLayout(views::BoxLayout::kHorizontal, 110 new views::BoxLayout(views::BoxLayout::kHorizontal,
112 kPadding, 111 kPadding,
113 0, 112 0,
114 kPadding - views::Textfield::kTextPadding); 113 kPadding - views::Textfield::kTextPadding);
115 SetLayoutManager(layout); 114 content_container_->SetLayoutManager(layout);
116 layout->set_cross_axis_alignment( 115 layout->set_cross_axis_alignment(
117 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 116 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
118 layout->set_minimum_cross_axis_size(kPreferredHeight); 117 layout->set_minimum_cross_axis_size(kPreferredHeight);
119 118
120 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 119 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
121 120
122 search_box_->SetBorder(views::Border::NullBorder()); 121 search_box_->SetBorder(views::Border::NullBorder());
123 search_box_->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); 122 search_box_->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont));
124 search_box_->set_placeholder_text_color(kHintTextColor); 123 search_box_->set_placeholder_text_color(kHintTextColor);
125 search_box_->set_controller(this); 124 search_box_->set_controller(this);
126 AddChildView(search_box_); 125 content_container_->AddChildView(search_box_);
127 layout->SetFlexForView(search_box_, 1); 126 layout->SetFlexForView(search_box_, 1);
128 127
129 #if !defined(OS_CHROMEOS) 128 #if !defined(OS_CHROMEOS)
130 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); 129 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false);
131 menu_button_->SetBorder(views::Border::NullBorder()); 130 menu_button_->SetBorder(views::Border::NullBorder());
132 menu_button_->SetImage(views::Button::STATE_NORMAL, 131 menu_button_->SetImage(views::Button::STATE_NORMAL,
133 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); 132 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL));
134 menu_button_->SetImage(views::Button::STATE_HOVERED, 133 menu_button_->SetImage(views::Button::STATE_HOVERED,
135 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); 134 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER));
136 menu_button_->SetImage(views::Button::STATE_PRESSED, 135 menu_button_->SetImage(views::Button::STATE_PRESSED,
137 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_PRESSED)); 136 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_PRESSED));
138 AddChildView(menu_button_); 137 content_container_->AddChildView(menu_button_);
139 #endif 138 #endif
140 139
141 view_delegate_->GetSpeechUI()->AddObserver(this); 140 view_delegate_->GetSpeechUI()->AddObserver(this);
142 ModelChanged(); 141 ModelChanged();
143 } 142 }
144 143
145 SearchBoxView::~SearchBoxView() { 144 SearchBoxView::~SearchBoxView() {
146 view_delegate_->GetSpeechUI()->RemoveObserver(this); 145 view_delegate_->GetSpeechUI()->RemoveObserver(this);
147 model_->search_box()->RemoveObserver(this); 146 model_->search_box()->RemoveObserver(this);
148 } 147 }
(...skipping 20 matching lines...) Expand all
169 // Updates model and fires query changed manually because SetText() above 168 // Updates model and fires query changed manually because SetText() above
170 // does not generate ContentsChanged() notification. 169 // does not generate ContentsChanged() notification.
171 UpdateModel(); 170 UpdateModel();
172 NotifyQueryChanged(); 171 NotifyQueryChanged();
173 } 172 }
174 173
175 void SearchBoxView::InvalidateMenu() { 174 void SearchBoxView::InvalidateMenu() {
176 menu_.reset(); 175 menu_.reset();
177 } 176 }
178 177
178 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds(
179 const gfx::Rect& rect) const {
180 gfx::Rect view_bounds = rect;
181 view_bounds.Inset(GetInsets().Scale(-1));
182 return view_bounds;
183 }
184
179 gfx::Size SearchBoxView::GetPreferredSize() const { 185 gfx::Size SearchBoxView::GetPreferredSize() const {
180 return gfx::Size(kPreferredWidth, kPreferredHeight); 186 return gfx::Size(kPreferredWidth, kPreferredHeight);
181 } 187 }
182 188
183 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { 189 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) {
184 if (contents_view_) 190 if (contents_view_)
185 return contents_view_->OnMouseWheel(event); 191 return contents_view_->OnMouseWheel(event);
186 192
187 return false; 193 return false;
188 } 194 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (icon_view_) 261 if (icon_view_)
256 icon_view_->SetImage(model_->search_box()->icon()); 262 icon_view_->SetImage(model_->search_box()->icon());
257 } 263 }
258 264
259 void SearchBoxView::SpeechRecognitionButtonPropChanged() { 265 void SearchBoxView::SpeechRecognitionButtonPropChanged() {
260 const SearchBoxModel::SpeechButtonProperty* speech_button_prop = 266 const SearchBoxModel::SpeechButtonProperty* speech_button_prop =
261 model_->search_box()->speech_button(); 267 model_->search_box()->speech_button();
262 if (speech_button_prop) { 268 if (speech_button_prop) {
263 if (!speech_button_) { 269 if (!speech_button_) {
264 speech_button_ = new views::ImageButton(this); 270 speech_button_ = new views::ImageButton(this);
265 AddChildView(speech_button_); 271 content_container_->AddChildView(speech_button_);
266 } 272 }
267 273
268 if (view_delegate_->GetSpeechUI()->state() == 274 if (view_delegate_->GetSpeechUI()->state() ==
269 SPEECH_RECOGNITION_HOTWORD_LISTENING) { 275 SPEECH_RECOGNITION_HOTWORD_LISTENING) {
270 speech_button_->SetImage( 276 speech_button_->SetImage(
271 views::Button::STATE_NORMAL, &speech_button_prop->on_icon); 277 views::Button::STATE_NORMAL, &speech_button_prop->on_icon);
272 speech_button_->SetTooltipText(speech_button_prop->on_tooltip); 278 speech_button_->SetTooltipText(speech_button_prop->on_tooltip);
273 } else { 279 } else {
274 speech_button_->SetImage( 280 speech_button_->SetImage(
275 views::Button::STATE_NORMAL, &speech_button_prop->off_icon); 281 views::Button::STATE_NORMAL, &speech_button_prop->off_icon);
(...skipping 22 matching lines...) Expand all
298 NotifyQueryChanged(); 304 NotifyQueryChanged();
299 } 305 }
300 306
301 void SearchBoxView::OnSpeechRecognitionStateChanged( 307 void SearchBoxView::OnSpeechRecognitionStateChanged(
302 SpeechRecognitionState new_state) { 308 SpeechRecognitionState new_state) {
303 SpeechRecognitionButtonPropChanged(); 309 SpeechRecognitionButtonPropChanged();
304 SchedulePaint(); 310 SchedulePaint();
305 } 311 }
306 312
307 } // namespace app_list 313 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698