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

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

Issue 493293003: Use a background for the main search box in the experimental app list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change constants to be closer to mocks Created 6 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 | Annotate | Revision Log
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_model.h" 9 #include "ui/app_list/app_list_model.h"
10 #include "ui/app_list/app_list_switches.h"
10 #include "ui/app_list/app_list_view_delegate.h" 11 #include "ui/app_list/app_list_view_delegate.h"
11 #include "ui/app_list/search_box_model.h" 12 #include "ui/app_list/search_box_model.h"
12 #include "ui/app_list/speech_ui_model.h" 13 #include "ui/app_list/speech_ui_model.h"
13 #include "ui/app_list/views/app_list_menu_views.h" 14 #include "ui/app_list/views/app_list_menu_views.h"
14 #include "ui/app_list/views/search_box_view_delegate.h" 15 #include "ui/app_list/views/search_box_view_delegate.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/events/event.h" 17 #include "ui/events/event.h"
18 #include "ui/gfx/canvas.h"
17 #include "ui/resources/grit/ui_resources.h" 19 #include "ui/resources/grit/ui_resources.h"
18 #include "ui/views/border.h" 20 #include "ui/views/border.h"
19 #include "ui/views/controls/button/image_button.h" 21 #include "ui/views/controls/button/image_button.h"
20 #include "ui/views/controls/button/menu_button.h" 22 #include "ui/views/controls/button/menu_button.h"
21 #include "ui/views/controls/image_view.h" 23 #include "ui/views/controls/image_view.h"
22 #include "ui/views/controls/textfield/textfield.h" 24 #include "ui/views/controls/textfield/textfield.h"
23 25
24 namespace app_list { 26 namespace app_list {
25 27
26 namespace { 28 namespace {
27 29
28 const int kPadding = 14; 30 const int kPadding = 14;
29 const int kIconDimension = 32; 31 const int kIconDimension = 32;
30 const int kPreferredWidth = 360; 32 const int kPreferredWidth = 360;
31 const int kPreferredHeight = 48; 33 const int kPreferredHeight = 48;
32 #if !defined(OS_CHROMEOS) 34 #if !defined(OS_CHROMEOS)
33 const int kMenuButtonDimension = 29; 35 const int kMenuButtonDimension = 29;
34 #endif 36 #endif
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
44 // Experimental app list constants.
45 const int kExperimentalSearchBoxHeight = 37;
46
47 const int kExperimentalBorderWidth = 1;
48 const int kExperimentalBorderBottomWidth = 2;
49 const int kExperimentalBorderCornerRadius = 2;
50 const SkColor kExperimentalBorderColor = SkColorSetRGB(0xEE, 0xEE, 0xEE);
51
52 // A background that paints a solid white rounded rect with a thin grey border.
53 class ExperimentalBackground : public views::Background {
Matt Giuca 2014/08/25 05:15:25 Same here: Call this BorderedBackground or similar
calamity 2014/08/26 01:16:30 Done. I don't think the comment will be necessary.
54 public:
55 ExperimentalBackground() {}
56 virtual ~ExperimentalBackground() {}
57
58 private:
59 // views::Background overrides:
60 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
61 gfx::Rect bounds = view->GetContentsBounds();
62
63 SkPaint paint;
64 paint.setFlags(SkPaint::kAntiAlias_Flag);
65 paint.setColor(kExperimentalBorderColor);
66 canvas->DrawRoundRect(bounds, kExperimentalBorderCornerRadius, paint);
67 bounds.Inset(kExperimentalBorderWidth,
68 kExperimentalBorderWidth,
69 kExperimentalBorderWidth,
70 kExperimentalBorderBottomWidth);
71 paint.setColor(SK_ColorWHITE);
72 canvas->DrawRoundRect(bounds, kExperimentalBorderCornerRadius, paint);
73 }
74
75 DISALLOW_COPY_AND_ASSIGN(ExperimentalBackground);
76 };
77
42 } // namespace 78 } // namespace
43 79
44 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, 80 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
45 AppListViewDelegate* view_delegate) 81 AppListViewDelegate* view_delegate)
46 : delegate_(delegate), 82 : delegate_(delegate),
47 view_delegate_(view_delegate), 83 view_delegate_(view_delegate),
48 model_(NULL), 84 model_(NULL),
49 icon_view_(new views::ImageView), 85 icon_view_(new views::ImageView),
50 speech_button_(NULL), 86 speech_button_(NULL),
51 search_box_(new views::Textfield), 87 search_box_(new views::Textfield),
52 contents_view_(NULL) { 88 contents_view_(NULL) {
53 AddChildView(icon_view_); 89 AddChildView(icon_view_);
90 if (switches::IsExperimentalAppListEnabled())
91 set_background(new ExperimentalBackground());
54 92
55 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 93 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
56 94
57 #if !defined(OS_CHROMEOS) 95 #if !defined(OS_CHROMEOS)
58 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); 96 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false);
59 menu_button_->SetBorder(views::Border::NullBorder()); 97 menu_button_->SetBorder(views::Border::NullBorder());
60 menu_button_->SetImage(views::Button::STATE_NORMAL, 98 menu_button_->SetImage(views::Button::STATE_NORMAL,
61 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); 99 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL));
62 menu_button_->SetImage(views::Button::STATE_HOVERED, 100 menu_button_->SetImage(views::Button::STATE_HOVERED,
63 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); 101 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // does not generate ContentsChanged() notification. 142 // does not generate ContentsChanged() notification.
105 UpdateModel(); 143 UpdateModel();
106 NotifyQueryChanged(); 144 NotifyQueryChanged();
107 } 145 }
108 146
109 void SearchBoxView::InvalidateMenu() { 147 void SearchBoxView::InvalidateMenu() {
110 menu_.reset(); 148 menu_.reset();
111 } 149 }
112 150
113 gfx::Size SearchBoxView::GetPreferredSize() const { 151 gfx::Size SearchBoxView::GetPreferredSize() const {
114 return gfx::Size(kPreferredWidth, kPreferredHeight); 152 return gfx::Size(kPreferredWidth,
153 switches::IsExperimentalAppListEnabled()
154 ? kExperimentalSearchBoxHeight
155 : kPreferredHeight);
115 } 156 }
116 157
117 void SearchBoxView::Layout() { 158 void SearchBoxView::Layout() {
118 gfx::Rect rect(GetContentsBounds()); 159 gfx::Rect rect(GetContentsBounds());
119 if (rect.IsEmpty()) 160 if (rect.IsEmpty())
120 return; 161 return;
121 162
122 gfx::Rect icon_frame(rect); 163 gfx::Rect icon_frame(rect);
123 icon_frame.set_width(kIconDimension + 2 * kPadding); 164 icon_frame.set_width(kIconDimension + 2 * kPadding);
124 icon_view_->SetBoundsRect(icon_frame); 165 icon_view_->SetBoundsRect(icon_frame);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 NotifyQueryChanged(); 296 NotifyQueryChanged();
256 } 297 }
257 298
258 void SearchBoxView::OnSpeechRecognitionStateChanged( 299 void SearchBoxView::OnSpeechRecognitionStateChanged(
259 SpeechRecognitionState new_state) { 300 SpeechRecognitionState new_state) {
260 SpeechRecognitionButtonPropChanged(); 301 SpeechRecognitionButtonPropChanged();
261 SchedulePaint(); 302 SchedulePaint();
262 } 303 }
263 304
264 } // namespace app_list 305 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698