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/app_list_view.h" | 5 #include "ui/app_list/views/app_list_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "ui/app_list/views/app_list_view_observer.h" | 21 #include "ui/app_list/views/app_list_view_observer.h" |
22 #include "ui/app_list/views/apps_container_view.h" | 22 #include "ui/app_list/views/apps_container_view.h" |
23 #include "ui/app_list/views/contents_view.h" | 23 #include "ui/app_list/views/contents_view.h" |
24 #include "ui/app_list/views/search_box_view.h" | 24 #include "ui/app_list/views/search_box_view.h" |
25 #include "ui/app_list/views/signin_view.h" | 25 #include "ui/app_list/views/signin_view.h" |
26 #include "ui/app_list/views/speech_view.h" | 26 #include "ui/app_list/views/speech_view.h" |
27 #include "ui/base/ui_base_switches.h" | 27 #include "ui/base/ui_base_switches.h" |
28 #include "ui/compositor/layer.h" | 28 #include "ui/compositor/layer.h" |
29 #include "ui/compositor/layer_animation_observer.h" | 29 #include "ui/compositor/layer_animation_observer.h" |
30 #include "ui/compositor/scoped_layer_animation_settings.h" | 30 #include "ui/compositor/scoped_layer_animation_settings.h" |
31 #include "ui/gfx/canvas.h" | |
31 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
32 #include "ui/gfx/insets.h" | 33 #include "ui/gfx/insets.h" |
33 #include "ui/gfx/path.h" | 34 #include "ui/gfx/path.h" |
34 #include "ui/gfx/skia_util.h" | 35 #include "ui/gfx/skia_util.h" |
35 #include "ui/views/bubble/bubble_frame_view.h" | 36 #include "ui/views/bubble/bubble_frame_view.h" |
36 #include "ui/views/bubble/bubble_window_targeter.h" | 37 #include "ui/views/bubble/bubble_window_targeter.h" |
37 #include "ui/views/controls/textfield/textfield.h" | 38 #include "ui/views/controls/textfield/textfield.h" |
38 #include "ui/views/layout/fill_layout.h" | 39 #include "ui/views/layout/fill_layout.h" |
39 #include "ui/views/widget/widget.h" | 40 #include "ui/views/widget/widget.h" |
40 | 41 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 switches::kDisableDwmComposition)) { | 74 switches::kDisableDwmComposition)) { |
74 return false; | 75 return false; |
75 } | 76 } |
76 #elif defined(OS_LINUX) && !defined(USE_ASH) | 77 #elif defined(OS_LINUX) && !defined(USE_ASH) |
77 // Shadows are not supported on (non-ChromeOS) Linux. | 78 // Shadows are not supported on (non-ChromeOS) Linux. |
78 return false; | 79 return false; |
79 #endif | 80 #endif |
80 return true; | 81 return true; |
81 } | 82 } |
82 | 83 |
84 // An background for a view that appears as a colored rounded rectangle with the | |
85 // given radius and the same size as the target view. | |
86 class ColoredRoundRectBackground : public views::Background { | |
87 public: | |
88 ColoredRoundRectBackground(int corner_radius, SkColor color) | |
89 : corner_radius_(corner_radius), color_(color) {}; | |
90 virtual ~ColoredRoundRectBackground() {}; | |
91 | |
92 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | |
93 SkPaint paint; | |
94 paint.setStyle(SkPaint::kFill_Style); | |
95 paint.setColor(color_); | |
96 canvas->DrawRoundRect(view->GetContentsBounds(), corner_radius_, paint); | |
97 } | |
98 | |
99 private: | |
100 const int corner_radius_; | |
101 const SkColor color_; | |
102 }; | |
103 | |
83 } // namespace | 104 } // namespace |
84 | 105 |
85 // An animation observer to hide the view at the end of the animation. | 106 // An animation observer to hide the view at the end of the animation. |
86 class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { | 107 class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { |
87 public: | 108 public: |
88 HideViewAnimationObserver() | 109 HideViewAnimationObserver() |
89 : frame_(NULL), | 110 : frame_(NULL), |
90 target_(NULL) { | 111 target_(NULL) { |
91 } | 112 } |
92 | 113 |
(...skipping 29 matching lines...) Expand all Loading... | |
122 }; | 143 }; |
123 | 144 |
124 //////////////////////////////////////////////////////////////////////////////// | 145 //////////////////////////////////////////////////////////////////////////////// |
125 // AppListView: | 146 // AppListView: |
126 | 147 |
127 AppListView::AppListView(AppListViewDelegate* delegate) | 148 AppListView::AppListView(AppListViewDelegate* delegate) |
128 : delegate_(delegate), | 149 : delegate_(delegate), |
129 app_list_main_view_(NULL), | 150 app_list_main_view_(NULL), |
130 signin_view_(NULL), | 151 signin_view_(NULL), |
131 speech_view_(NULL), | 152 speech_view_(NULL), |
153 overlay_view_(NULL), | |
132 animation_observer_(new HideViewAnimationObserver()) { | 154 animation_observer_(new HideViewAnimationObserver()) { |
133 CHECK(delegate); | 155 CHECK(delegate); |
134 | 156 |
135 delegate_->AddObserver(this); | 157 delegate_->AddObserver(this); |
136 delegate_->GetSpeechUI()->AddObserver(this); | 158 delegate_->GetSpeechUI()->AddObserver(this); |
137 } | 159 } |
138 | 160 |
139 AppListView::~AppListView() { | 161 AppListView::~AppListView() { |
140 delegate_->GetSpeechUI()->RemoveObserver(this); | 162 delegate_->GetSpeechUI()->RemoveObserver(this); |
141 delegate_->RemoveObserver(this); | 163 delegate_->RemoveObserver(this); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 | 211 |
190 void AppListView::Close() { | 212 void AppListView::Close() { |
191 app_list_main_view_->Close(); | 213 app_list_main_view_->Close(); |
192 delegate_->Dismiss(); | 214 delegate_->Dismiss(); |
193 } | 215 } |
194 | 216 |
195 void AppListView::UpdateBounds() { | 217 void AppListView::UpdateBounds() { |
196 SizeToContents(); | 218 SizeToContents(); |
197 } | 219 } |
198 | 220 |
221 void AppListView::ShowAppListOverlay(bool visible) { | |
222 if (overlay_view_ == NULL) { | |
calamity
2014/05/16 05:54:32
Any reason not to just construct this in the initi
sashab
2014/05/19 07:24:53
Originally I thought it would be a memory leak - i
calamity
2014/05/20 01:25:17
Actually, you're right. Better to DCHECK overlay_v
| |
223 // The contents corner radius is 1px smaller than border corner radius. | |
224 const int kOverlayCornerRadius = | |
225 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius() - 1; | |
calamity
2014/05/16 05:54:32
Good news! Since this is a view inside the bubble
sashab
2014/05/19 07:24:53
Cool!!!
| |
226 const float kOverlayOpacity = 0.75f; | |
227 | |
228 // To make the overlay view, construct a regular view with | |
229 // ColoredRoundRectBackground as the background. This is because we need | |
230 // overlay_view_ to be drawn to its own layer (so it appears correctly in | |
231 // the foreground), but we also need a custom Paint() method to draw our | |
232 // custom rounded rectangle (View::Paint() is not called when | |
233 // SetPaintToLayer is true). | |
234 overlay_view_ = new views::View(); | |
235 overlay_view_->SetPaintToLayer(true); | |
236 overlay_view_->set_background( | |
237 new ColoredRoundRectBackground(kOverlayCornerRadius, SK_ColorWHITE)); | |
calamity
2014/05/16 05:54:32
That means you can get away with views::Background
sashab
2014/05/19 07:24:53
Nice!! Done.
| |
238 overlay_view_->layer()->SetOpacity(kOverlayOpacity); | |
239 overlay_view_->SetBoundsRect(bounds()); | |
240 | |
241 // Add this view to the 'front' of the screen (end of the child view list). | |
242 AddChildViewAt(overlay_view_, this->child_count()); | |
calamity
2014/05/16 05:54:32
This is equivalent to AddChildView().
sashab
2014/05/19 07:24:53
So it is. Thanks.
| |
243 } | |
244 overlay_view_->SetVisible(visible); | |
245 } | |
246 | |
199 bool AppListView::ShouldCenterWindow() const { | 247 bool AppListView::ShouldCenterWindow() const { |
200 return delegate_->ShouldCenterWindow(); | 248 return delegate_->ShouldCenterWindow(); |
201 } | 249 } |
202 | 250 |
203 gfx::Size AppListView::GetPreferredSize() { | 251 gfx::Size AppListView::GetPreferredSize() { |
204 return app_list_main_view_->GetPreferredSize(); | 252 return app_list_main_view_->GetPreferredSize(); |
205 } | 253 } |
206 | 254 |
207 void AppListView::Paint(gfx::Canvas* canvas) { | 255 void AppListView::Paint(gfx::Canvas* canvas) { |
208 views::BubbleDelegateView::Paint(canvas); | 256 views::BubbleDelegateView::Paint(canvas); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 #else | 561 #else |
514 speech_view_->SetVisible(recognizing); | 562 speech_view_->SetVisible(recognizing); |
515 app_list_main_view_->SetVisible(!recognizing); | 563 app_list_main_view_->SetVisible(!recognizing); |
516 | 564 |
517 // Needs to schedule paint of AppListView itself, to repaint the background. | 565 // Needs to schedule paint of AppListView itself, to repaint the background. |
518 GetBubbleFrameView()->SchedulePaint(); | 566 GetBubbleFrameView()->SchedulePaint(); |
519 #endif | 567 #endif |
520 } | 568 } |
521 | 569 |
522 } // namespace app_list | 570 } // namespace app_list |
OLD | NEW |