OLD | NEW |
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_model.h" | 10 #include "ui/app_list/app_list_model.h" |
10 #include "ui/app_list/app_list_switches.h" | 11 #include "ui/app_list/app_list_switches.h" |
11 #include "ui/app_list/app_list_view_delegate.h" | 12 #include "ui/app_list/app_list_view_delegate.h" |
12 #include "ui/app_list/search_box_model.h" | 13 #include "ui/app_list/search_box_model.h" |
13 #include "ui/app_list/speech_ui_model.h" | 14 #include "ui/app_list/speech_ui_model.h" |
14 #include "ui/app_list/views/app_list_menu_views.h" | 15 #include "ui/app_list/views/app_list_menu_views.h" |
15 #include "ui/app_list/views/search_box_view_delegate.h" | 16 #include "ui/app_list/views/search_box_view_delegate.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
(...skipping 19 matching lines...) Expand all Loading... |
38 const int kMenuYOffsetFromButton = -4; | 39 const int kMenuYOffsetFromButton = -4; |
39 const int kMenuXOffsetFromButton = -7; | 40 const int kMenuXOffsetFromButton = -7; |
40 | 41 |
41 const int kBackgroundBorderWidth = 1; | 42 const int kBackgroundBorderWidth = 1; |
42 const int kBackgroundBorderBottomWidth = 1; | 43 const int kBackgroundBorderBottomWidth = 1; |
43 const int kBackgroundBorderCornerRadius = 2; | 44 const int kBackgroundBorderCornerRadius = 2; |
44 const SkColor kBackgroundBorderColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); | 45 const SkColor kBackgroundBorderColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); |
45 const SkColor kBackgroundBorderBottomColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); | 46 const SkColor kBackgroundBorderBottomColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); |
46 | 47 |
47 // A background that paints a solid white rounded rect with a thin grey border. | 48 // A background that paints a solid white rounded rect with a thin grey border. |
48 class SearchBoxBackground : public views::Background { | 49 class ExperimentalSearchBoxBackground : public views::Background { |
49 public: | 50 public: |
50 SearchBoxBackground() {} | 51 ExperimentalSearchBoxBackground() {} |
51 virtual ~SearchBoxBackground() {} | 52 virtual ~ExperimentalSearchBoxBackground() {} |
52 | 53 |
53 private: | 54 private: |
54 // views::Background overrides: | 55 // views::Background overrides: |
55 virtual void Paint(gfx::Canvas* canvas, views::View* view) const override { | 56 virtual void Paint(gfx::Canvas* canvas, views::View* view) const override { |
56 gfx::Rect bounds = view->GetContentsBounds(); | 57 gfx::Rect bounds = view->GetContentsBounds(); |
57 | 58 |
58 SkPaint paint; | 59 SkPaint paint; |
59 paint.setFlags(SkPaint::kAntiAlias_Flag); | 60 paint.setFlags(SkPaint::kAntiAlias_Flag); |
60 paint.setColor(kBackgroundBorderColor); | 61 paint.setColor(kBackgroundBorderColor); |
61 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint); | 62 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint); |
62 bounds.Inset(kBackgroundBorderWidth, | 63 bounds.Inset(kBackgroundBorderWidth, |
63 kBackgroundBorderWidth, | 64 kBackgroundBorderWidth, |
64 kBackgroundBorderWidth, | 65 kBackgroundBorderWidth, |
65 0); | 66 0); |
66 paint.setColor(kBackgroundBorderBottomColor); | 67 paint.setColor(kBackgroundBorderBottomColor); |
67 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint); | 68 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint); |
68 bounds.Inset(0, 0, 0, kBackgroundBorderBottomWidth); | 69 bounds.Inset(0, 0, 0, kBackgroundBorderBottomWidth); |
69 paint.setColor(SK_ColorWHITE); | 70 paint.setColor(kSearchBoxBackground); |
70 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint); | 71 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, paint); |
71 } | 72 } |
72 | 73 |
73 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); | 74 DISALLOW_COPY_AND_ASSIGN(ExperimentalSearchBoxBackground); |
74 }; | 75 }; |
75 | 76 |
76 } // namespace | 77 } // namespace |
77 | 78 |
78 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 79 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, |
79 AppListViewDelegate* view_delegate) | 80 AppListViewDelegate* view_delegate) |
80 : delegate_(delegate), | 81 : delegate_(delegate), |
81 view_delegate_(view_delegate), | 82 view_delegate_(view_delegate), |
82 model_(NULL), | 83 model_(NULL), |
83 icon_view_(NULL), | 84 icon_view_(NULL), |
84 speech_button_(NULL), | 85 speech_button_(NULL), |
85 search_box_(new views::Textfield), | 86 search_box_(new views::Textfield), |
86 contents_view_(NULL) { | 87 contents_view_(NULL) { |
87 if (switches::IsExperimentalAppListEnabled()) { | 88 if (switches::IsExperimentalAppListEnabled()) { |
88 set_background(new SearchBoxBackground()); | 89 set_background(new ExperimentalSearchBoxBackground()); |
89 } else { | 90 } else { |
| 91 set_background( |
| 92 views::Background::CreateSolidBackground(kSearchBoxBackground)); |
| 93 SetBorder( |
| 94 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kTopSeparatorColor)); |
90 icon_view_ = new views::ImageView; | 95 icon_view_ = new views::ImageView; |
91 AddChildView(icon_view_); | 96 AddChildView(icon_view_); |
92 } | 97 } |
93 | 98 |
94 views::BoxLayout* layout = | 99 views::BoxLayout* layout = |
95 new views::BoxLayout(views::BoxLayout::kHorizontal, | 100 new views::BoxLayout(views::BoxLayout::kHorizontal, |
96 kPadding, | 101 kPadding, |
97 0, | 102 0, |
98 kPadding - views::Textfield::kTextPadding); | 103 kPadding - views::Textfield::kTextPadding); |
99 SetLayoutManager(layout); | 104 SetLayoutManager(layout); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 NotifyQueryChanged(); | 267 NotifyQueryChanged(); |
263 } | 268 } |
264 | 269 |
265 void SearchBoxView::OnSpeechRecognitionStateChanged( | 270 void SearchBoxView::OnSpeechRecognitionStateChanged( |
266 SpeechRecognitionState new_state) { | 271 SpeechRecognitionState new_state) { |
267 SpeechRecognitionButtonPropChanged(); | 272 SpeechRecognitionButtonPropChanged(); |
268 SchedulePaint(); | 273 SchedulePaint(); |
269 } | 274 } |
270 | 275 |
271 } // namespace app_list | 276 } // namespace app_list |
OLD | NEW |