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

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

Issue 2898743002: Draggable peeking/fullscreen launcher with transparent background. (Closed)
Patch Set: addressed msw@'s comments. Created 3 years, 6 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 "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 "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "ui/app_list/app_list_constants.h" 12 #include "ui/app_list/app_list_constants.h"
13 #include "ui/app_list/app_list_features.h"
13 #include "ui/app_list/app_list_model.h" 14 #include "ui/app_list/app_list_model.h"
14 #include "ui/app_list/app_list_switches.h" 15 #include "ui/app_list/app_list_switches.h"
15 #include "ui/app_list/app_list_view_delegate.h" 16 #include "ui/app_list/app_list_view_delegate.h"
16 #include "ui/app_list/resources/grit/app_list_resources.h" 17 #include "ui/app_list/resources/grit/app_list_resources.h"
17 #include "ui/app_list/search_box_model.h" 18 #include "ui/app_list/search_box_model.h"
18 #include "ui/app_list/speech_ui_model.h" 19 #include "ui/app_list/speech_ui_model.h"
20 #include "ui/app_list/views/app_list_view.h"
19 #include "ui/app_list/views/contents_view.h" 21 #include "ui/app_list/views/contents_view.h"
20 #include "ui/app_list/views/search_box_view_delegate.h" 22 #include "ui/app_list/views/search_box_view_delegate.h"
21 #include "ui/base/ime/text_input_flags.h" 23 #include "ui/base/ime/text_input_flags.h"
22 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/events/event.h" 26 #include "ui/events/event.h"
25 #include "ui/gfx/canvas.h" 27 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/shadow_value.h" 28 #include "ui/gfx/shadow_value.h"
27 #include "ui/strings/grit/ui_strings.h" 29 #include "ui/strings/grit/ui_strings.h"
28 #include "ui/views/background.h" 30 #include "ui/views/background.h"
29 #include "ui/views/border.h" 31 #include "ui/views/border.h"
30 #include "ui/views/controls/button/image_button.h" 32 #include "ui/views/controls/button/image_button.h"
31 #include "ui/views/controls/image_view.h" 33 #include "ui/views/controls/image_view.h"
32 #include "ui/views/controls/textfield/textfield.h" 34 #include "ui/views/controls/textfield/textfield.h"
33 #include "ui/views/layout/box_layout.h" 35 #include "ui/views/layout/box_layout.h"
34 #include "ui/views/layout/fill_layout.h" 36 #include "ui/views/layout/fill_layout.h"
35 #include "ui/views/shadow_border.h" 37 #include "ui/views/shadow_border.h"
38 #include "ui/views/widget/widget.h"
36 39
37 namespace app_list { 40 namespace app_list {
38 41
39 namespace { 42 namespace {
40 43
41 const int kPadding = 16; 44 const int kPadding = 16;
42 const int kInnerPadding = 24; 45 const int kInnerPadding = 24;
43 const int kPreferredWidth = 360; 46 const int kPreferredWidth = 360;
47 const int kPreferredWidthFullscreen = 544;
44 const int kPreferredHeight = 48; 48 const int kPreferredHeight = 48;
45 49
46 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); 50 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0);
47 51
48 const int kBackgroundBorderCornerRadius = 2; 52 const int kBackgroundBorderCornerRadius = 2;
53 const int kBackgroundBorderCornerRadiusFullscreen = 20;
54
55 bool IsFullscreenAppListEnabled() {
56 // Cache this value to avoid repeated lookup.
57 static bool cached_value = features::IsFullscreenAppListEnabled();
58 return cached_value;
59 }
49 60
50 // A background that paints a solid white rounded rect with a thin grey border. 61 // A background that paints a solid white rounded rect with a thin grey border.
51 class SearchBoxBackground : public views::Background { 62 class SearchBoxBackground : public views::Background {
52 public: 63 public:
53 SearchBoxBackground() {} 64 SearchBoxBackground()
65 : background_border_corner_radius_(
66 IsFullscreenAppListEnabled()
67 ? kBackgroundBorderCornerRadiusFullscreen
68 : kBackgroundBorderCornerRadius) {}
54 ~SearchBoxBackground() override {} 69 ~SearchBoxBackground() override {}
55 70
56 private: 71 private:
57 // views::Background overrides: 72 // views::Background overrides:
58 void Paint(gfx::Canvas* canvas, views::View* view) const override { 73 void Paint(gfx::Canvas* canvas, views::View* view) const override {
59 gfx::Rect bounds = view->GetContentsBounds(); 74 gfx::Rect bounds = view->GetContentsBounds();
60 75
61 cc::PaintFlags flags; 76 cc::PaintFlags flags;
62 flags.setAntiAlias(true); 77 flags.setAntiAlias(true);
63 flags.setColor(kSearchBoxBackground); 78 flags.setColor(kSearchBoxBackground);
64 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, flags); 79 canvas->DrawRoundRect(bounds, background_border_corner_radius_, flags);
65 } 80 }
66 81
82 const int background_border_corner_radius_;
83
67 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); 84 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground);
68 }; 85 };
69 86
70 } // namespace 87 } // namespace
71 88
72 // To paint grey background on mic and back buttons 89 // To paint grey background on mic and back buttons
73 class SearchBoxImageButton : public views::ImageButton { 90 class SearchBoxImageButton : public views::ImageButton {
74 public: 91 public:
75 explicit SearchBoxImageButton(views::ButtonListener* listener) 92 explicit SearchBoxImageButton(views::ButtonListener* listener)
76 : ImageButton(listener), selected_(false) {} 93 : ImageButton(listener), selected_(false) {}
(...skipping 29 matching lines...) Expand all
106 } 123 }
107 124
108 const char* GetClassName() const override { return "SearchBoxImageButton"; } 125 const char* GetClassName() const override { return "SearchBoxImageButton"; }
109 126
110 bool selected_; 127 bool selected_;
111 128
112 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); 129 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton);
113 }; 130 };
114 131
115 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, 132 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
116 AppListViewDelegate* view_delegate) 133 AppListViewDelegate* view_delegate,
134 AppListView* app_list_view)
117 : delegate_(delegate), 135 : delegate_(delegate),
118 view_delegate_(view_delegate), 136 view_delegate_(view_delegate),
119 model_(NULL), 137 model_(NULL),
120 content_container_(new views::View), 138 content_container_(new views::View),
121 back_button_(NULL), 139 back_button_(NULL),
122 speech_button_(NULL), 140 speech_button_(NULL),
123 search_box_(new views::Textfield), 141 search_box_(new views::Textfield),
124 contents_view_(NULL), 142 contents_view_(NULL),
143 app_list_view_(app_list_view),
125 focused_view_(FOCUS_SEARCH_BOX) { 144 focused_view_(FOCUS_SEARCH_BOX) {
126 SetLayoutManager(new views::FillLayout); 145 SetLayoutManager(new views::FillLayout);
127 SetPreferredSize(gfx::Size(kPreferredWidth, kPreferredHeight)); 146 SetPreferredSize(gfx::Size(IsFullscreenAppListEnabled()
147 ? kPreferredWidthFullscreen
148 : kPreferredWidth,
149 kPreferredHeight));
128 AddChildView(content_container_); 150 AddChildView(content_container_);
129 151
130 SetShadow(GetShadowForZHeight(2)); 152 SetShadow(GetShadowForZHeight(2));
131 back_button_ = new SearchBoxImageButton(this); 153 back_button_ = new SearchBoxImageButton(this);
132 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 154 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
133 back_button_->SetImage(views::ImageButton::STATE_NORMAL, 155 back_button_->SetImage(views::ImageButton::STATE_NORMAL,
134 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); 156 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL));
135 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, 157 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
136 views::ImageButton::ALIGN_MIDDLE); 158 views::ImageButton::ALIGN_MIDDLE);
137 SetBackButtonLabel(false); 159 SetBackButtonLabel(false);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 void SearchBoxView::NotifyQueryChanged() { 337 void SearchBoxView::NotifyQueryChanged() {
316 DCHECK(delegate_); 338 DCHECK(delegate_);
317 delegate_->QueryChanged(this); 339 delegate_->QueryChanged(this);
318 } 340 }
319 341
320 void SearchBoxView::ContentsChanged(views::Textfield* sender, 342 void SearchBoxView::ContentsChanged(views::Textfield* sender,
321 const base::string16& new_contents) { 343 const base::string16& new_contents) {
322 UpdateModel(); 344 UpdateModel();
323 view_delegate_->AutoLaunchCanceled(); 345 view_delegate_->AutoLaunchCanceled();
324 NotifyQueryChanged(); 346 NotifyQueryChanged();
347
348 if (IsFullscreenAppListEnabled() && !app_list_view_->IsFullscreen()) {
349 // If the app list is in the peeking state, switch it to fullscreen.
350 app_list_view_->SetState(AppListView::FULLSCREEN);
351 }
325 } 352 }
326 353
327 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, 354 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
328 const ui::KeyEvent& key_event) { 355 const ui::KeyEvent& key_event) {
329 if (key_event.type() == ui::ET_KEY_PRESSED) { 356 if (key_event.type() == ui::ET_KEY_PRESSED) {
330 if (key_event.key_code() == ui::VKEY_TAB && 357 if (key_event.key_code() == ui::VKEY_TAB &&
331 focused_view_ != FOCUS_CONTENTS_VIEW && 358 focused_view_ != FOCUS_CONTENTS_VIEW &&
332 MoveTabFocus(key_event.IsShiftDown())) 359 MoveTabFocus(key_event.IsShiftDown()))
333 return true; 360 return true;
334 361
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 NotifyQueryChanged(); 457 NotifyQueryChanged();
431 } 458 }
432 459
433 void SearchBoxView::OnSpeechRecognitionStateChanged( 460 void SearchBoxView::OnSpeechRecognitionStateChanged(
434 SpeechRecognitionState new_state) { 461 SpeechRecognitionState new_state) {
435 SpeechRecognitionButtonPropChanged(); 462 SpeechRecognitionButtonPropChanged();
436 SchedulePaint(); 463 SchedulePaint();
437 } 464 }
438 465
439 } // namespace app_list 466 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698