Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 71 switches::kDisableDwmComposition)) { | 72 switches::kDisableDwmComposition)) { |
| 72 return false; | 73 return false; |
| 73 } | 74 } |
| 74 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) | 75 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 75 // Shadows are not supported on (non-ChromeOS) Linux. | 76 // Shadows are not supported on (non-ChromeOS) Linux. |
| 76 return false; | 77 return false; |
| 77 #endif | 78 #endif |
| 78 return true; | 79 return true; |
| 79 } | 80 } |
| 80 | 81 |
| 82 // An background for a view that appears as a colored rounded rectangle with the | |
|
tapted
2014/05/21 03:40:57
nit: An -> A
sashab
2014/05/22 07:20:21
Oops :) Done.
| |
| 83 // given radius and the same size as the target view. | |
| 84 class ColoredRoundRectBackground : public views::Background { | |
| 85 public: | |
| 86 ColoredRoundRectBackground(int corner_radius, SkColor color) | |
| 87 : corner_radius_(corner_radius), color_(color) {}; | |
| 88 virtual ~ColoredRoundRectBackground() {}; | |
| 89 | |
| 90 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | |
|
tapted
2014/05/21 03:40:57
nit: // Overridden from views::Background:
sashab
2014/05/22 07:20:21
Done.
| |
| 91 SkPaint paint; | |
| 92 paint.setStyle(SkPaint::kFill_Style); | |
| 93 paint.setColor(color_); | |
|
tapted
2014/05/21 03:40:57
this class is pretty specialized - I don't think t
sashab
2014/05/22 07:20:21
Yup, agreed. Done.
| |
| 94 canvas->DrawRoundRect(view->GetContentsBounds(), corner_radius_, paint); | |
| 95 } | |
| 96 | |
| 97 private: | |
| 98 const int corner_radius_; | |
| 99 const SkColor color_; | |
| 100 }; | |
|
tapted
2014/05/21 03:40:57
nit: DISALLOW_COPY_AND_ASSIGN(..)
sashab
2014/05/22 07:20:21
Done.
| |
| 101 | |
| 81 } // namespace | 102 } // namespace |
| 82 | 103 |
| 83 // An animation observer to hide the view at the end of the animation. | 104 // An animation observer to hide the view at the end of the animation. |
| 84 class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { | 105 class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { |
| 85 public: | 106 public: |
| 86 HideViewAnimationObserver() | 107 HideViewAnimationObserver() |
| 87 : frame_(NULL), | 108 : frame_(NULL), |
| 88 target_(NULL) { | 109 target_(NULL) { |
| 89 } | 110 } |
| 90 | 111 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 120 }; | 141 }; |
| 121 | 142 |
| 122 //////////////////////////////////////////////////////////////////////////////// | 143 //////////////////////////////////////////////////////////////////////////////// |
| 123 // AppListView: | 144 // AppListView: |
| 124 | 145 |
| 125 AppListView::AppListView(AppListViewDelegate* delegate) | 146 AppListView::AppListView(AppListViewDelegate* delegate) |
| 126 : delegate_(delegate), | 147 : delegate_(delegate), |
| 127 app_list_main_view_(NULL), | 148 app_list_main_view_(NULL), |
| 128 signin_view_(NULL), | 149 signin_view_(NULL), |
| 129 speech_view_(NULL), | 150 speech_view_(NULL), |
| 151 overlay_view_(NULL), | |
| 130 animation_observer_(new HideViewAnimationObserver()) { | 152 animation_observer_(new HideViewAnimationObserver()) { |
| 131 CHECK(delegate); | 153 CHECK(delegate); |
| 132 | 154 |
| 133 delegate_->AddObserver(this); | 155 delegate_->AddObserver(this); |
| 134 delegate_->GetSpeechUI()->AddObserver(this); | 156 delegate_->GetSpeechUI()->AddObserver(this); |
| 135 } | 157 } |
| 136 | 158 |
| 137 AppListView::~AppListView() { | 159 AppListView::~AppListView() { |
| 138 delegate_->GetSpeechUI()->RemoveObserver(this); | 160 delegate_->GetSpeechUI()->RemoveObserver(this); |
| 139 delegate_->RemoveObserver(this); | 161 delegate_->RemoveObserver(this); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 | 209 |
| 188 void AppListView::Close() { | 210 void AppListView::Close() { |
| 189 app_list_main_view_->Close(); | 211 app_list_main_view_->Close(); |
| 190 delegate_->Dismiss(); | 212 delegate_->Dismiss(); |
| 191 } | 213 } |
| 192 | 214 |
| 193 void AppListView::UpdateBounds() { | 215 void AppListView::UpdateBounds() { |
| 194 SizeToContents(); | 216 SizeToContents(); |
| 195 } | 217 } |
| 196 | 218 |
| 219 void AppListView::ShowAppListOverlay(bool visible) { | |
| 220 DCHECK(overlay_view_); | |
| 221 overlay_view_->SetVisible(visible); | |
| 222 } | |
| 223 | |
| 197 bool AppListView::ShouldCenterWindow() const { | 224 bool AppListView::ShouldCenterWindow() const { |
| 198 return delegate_->ShouldCenterWindow(); | 225 return delegate_->ShouldCenterWindow(); |
| 199 } | 226 } |
| 200 | 227 |
| 201 gfx::Size AppListView::GetPreferredSize() const { | 228 gfx::Size AppListView::GetPreferredSize() const { |
| 202 return app_list_main_view_->GetPreferredSize(); | 229 return app_list_main_view_->GetPreferredSize(); |
| 203 } | 230 } |
| 204 | 231 |
| 205 void AppListView::Paint(gfx::Canvas* canvas, const views::CullSet& cull_set) { | 232 void AppListView::Paint(gfx::Canvas* canvas, const views::CullSet& cull_set) { |
| 206 views::BubbleDelegateView::Paint(canvas, cull_set); | 233 views::BubbleDelegateView::Paint(canvas, cull_set); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 app_list_main_view_)); | 354 app_list_main_view_)); |
| 328 | 355 |
| 329 // On non-aura the bubble has two widgets, and it's possible for the border | 356 // On non-aura the bubble has two widgets, and it's possible for the border |
| 330 // to be shown independently in odd situations. Explicitly hide the bubble | 357 // to be shown independently in odd situations. Explicitly hide the bubble |
| 331 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the | 358 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the |
| 332 // window manager do not have the SWP_SHOWWINDOW flag set which would cause | 359 // window manager do not have the SWP_SHOWWINDOW flag set which would cause |
| 333 // the border to be shown. See http://crbug.com/231687 . | 360 // the border to be shown. See http://crbug.com/231687 . |
| 334 GetWidget()->Hide(); | 361 GetWidget()->Hide(); |
| 335 #endif | 362 #endif |
| 336 | 363 |
| 364 // The contents corner radius is 1px smaller than border corner radius. We | |
| 365 // need this for platforms where the bubble doesn't have a shadow (such as | |
| 366 // Linux aura and Windows XP). When the bubble does have a shadow, the view is | |
|
tapted
2014/05/21 03:40:57
I don't really understand this comment - seems to
sashab
2014/05/22 07:20:21
I didn't see SupportsShadow(). Thank you for that
| |
| 367 // modal to the dialog, so a solid background is sufficient. | |
| 368 const int kOverlayCornerRadius = | |
| 369 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius() - 1; | |
| 370 const float kOverlayOpacity = 0.75f; | |
| 371 | |
| 372 // To make the overlay view, construct a regular view with a solid white | |
| 373 // background, rather than a white rectangle on it. This is because we need | |
| 374 // overlay_view_ to be drawn to its own layer (so it appears correctly in the | |
| 375 // foreground). | |
| 376 overlay_view_ = new views::View(); | |
| 377 overlay_view_->SetPaintToLayer(true); | |
| 378 overlay_view_->set_background( | |
| 379 new ColoredRoundRectBackground(kOverlayCornerRadius, SK_ColorWHITE)); | |
| 380 overlay_view_->layer()->SetOpacity(kOverlayOpacity); | |
| 381 overlay_view_->SetBoundsRect(bounds()); | |
|
tapted
2014/05/21 03:40:57
Since this is a child view, it shouldn't use the s
sashab
2014/05/22 07:20:21
Ahh yup - this was only working because it was pos
| |
| 382 overlay_view_->SetVisible(false); | |
| 383 AddChildView(overlay_view_); | |
| 384 | |
| 337 if (delegate_) | 385 if (delegate_) |
| 338 delegate_->ViewInitialized(); | 386 delegate_->ViewInitialized(); |
| 339 } | 387 } |
| 340 | 388 |
| 341 void AppListView::OnBeforeBubbleWidgetInit( | 389 void AppListView::OnBeforeBubbleWidgetInit( |
| 342 views::Widget::InitParams* params, | 390 views::Widget::InitParams* params, |
| 343 views::Widget* widget) const { | 391 views::Widget* widget) const { |
| 344 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 392 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
| 345 if (delegate_ && delegate_->ForceNativeDesktop()) | 393 if (delegate_ && delegate_->ForceNativeDesktop()) |
| 346 params->native_widget = new views::DesktopNativeWidgetAura(widget); | 394 params->native_widget = new views::DesktopNativeWidgetAura(widget); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 #else | 559 #else |
| 512 speech_view_->SetVisible(recognizing); | 560 speech_view_->SetVisible(recognizing); |
| 513 app_list_main_view_->SetVisible(!recognizing); | 561 app_list_main_view_->SetVisible(!recognizing); |
| 514 | 562 |
| 515 // Needs to schedule paint of AppListView itself, to repaint the background. | 563 // Needs to schedule paint of AppListView itself, to repaint the background. |
| 516 GetBubbleFrameView()->SchedulePaint(); | 564 GetBubbleFrameView()->SchedulePaint(); |
| 517 #endif | 565 #endif |
| 518 } | 566 } |
| 519 | 567 |
| 520 } // namespace app_list | 568 } // namespace app_list |
| OLD | NEW |