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

Side by Side Diff: ash/system/tray/tray_background_view.cc

Issue 10854175: Revert 151752 - Move non SystemTray specific code to TrayBackgroundView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 "ash/system/tray/tray_background_view.h" 5 #include "ash/system/tray/tray_background_view.h"
6 6
7 #include "ash/launcher/background_animator.h" 7 #include "ash/launcher/background_animator.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/system/status_area_widget.h" 10 #include "ash/system/status_area_widget.h"
11 #include "ash/system/status_area_widget_delegate.h" 11 #include "ash/system/status_area_widget_delegate.h"
12 #include "ash/system/tray/tray_constants.h" 12 #include "ash/system/tray/tray_constants.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/compositor/layer_animation_observer.h"
15 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/skia_util.h" 15 #include "ui/gfx/skia_util.h"
17 #include "ui/views/background.h" 16 #include "ui/views/background.h"
18 #include "ui/views/layout/box_layout.h" 17 #include "ui/views/layout/box_layout.h"
19 18
20 namespace { 19 namespace {
21 20
22 const SkColor kTrayBackgroundAlpha = 100; 21 const SkColor kTrayBackgroundAlpha = 100;
23 const SkColor kTrayBackgroundHoverAlpha = 150; 22 const SkColor kTrayBackgroundHoverAlpha = 150;
24 23
25 // Adjust the size of TrayContainer with additional padding. 24 // Adjust the size of TrayContainer with additional padding.
26 const int kTrayContainerVerticalPaddingBottomAlignment = 1; 25 const int kTrayContainerVerticalPaddingBottomAlignment = 1;
27 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; 26 const int kTrayContainerHorizontalPaddingBottomAlignment = 1;
28 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; 27 const int kTrayContainerVerticalPaddingVerticalAlignment = 1;
29 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; 28 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1;
30 29
31 } // namespace 30 } // namespace
32 31
33 namespace ash { 32 namespace ash {
34 namespace internal { 33 namespace internal {
35 34
36 // Observe the tray layer animation and update the anchor when it changes.
37 // TODO(stevenjb): Observe or mirror the actual animation, not just the start
38 // and end points.
39 class TrayLayerAnimationObserver : public ui::LayerAnimationObserver {
40 public:
41 explicit TrayLayerAnimationObserver(TrayBackgroundView* host)
42 : host_(host) {
43 }
44
45 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) {
46 host_->AnchorUpdated();
47 }
48
49 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) {
50 host_->AnchorUpdated();
51 }
52
53 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) {
54 host_->AnchorUpdated();
55 }
56
57 private:
58 TrayBackgroundView* host_;
59
60 DISALLOW_COPY_AND_ASSIGN(TrayLayerAnimationObserver);
61 };
62
63 class TrayBackground : public views::Background { 35 class TrayBackground : public views::Background {
64 public: 36 public:
65 TrayBackground() : alpha_(kTrayBackgroundAlpha) {} 37 TrayBackground() : alpha_(kTrayBackgroundAlpha) {}
66 virtual ~TrayBackground() {} 38 virtual ~TrayBackground() {}
67 39
68 void set_alpha(int alpha) { alpha_ = alpha; } 40 void set_alpha(int alpha) { alpha_ = alpha; }
69 41
70 private: 42 private:
71 // Overridden from views::Background. 43 // Overridden from views::Background.
72 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { 44 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 124
153 TrayBackgroundView::TrayBackgroundView( 125 TrayBackgroundView::TrayBackgroundView(
154 internal::StatusAreaWidget* status_area_widget) 126 internal::StatusAreaWidget* status_area_widget)
155 : status_area_widget_(status_area_widget), 127 : status_area_widget_(status_area_widget),
156 tray_container_(NULL), 128 tray_container_(NULL),
157 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), 129 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
158 background_(NULL), 130 background_(NULL),
159 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_( 131 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(
160 this, 0, kTrayBackgroundAlpha)), 132 this, 0, kTrayBackgroundAlpha)),
161 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_( 133 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(
162 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)), 134 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) {
163 ALLOW_THIS_IN_INITIALIZER_LIST(layer_animation_observer_(
164 new TrayLayerAnimationObserver(this))) {
165 set_notify_enter_exit_on_child(true); 135 set_notify_enter_exit_on_child(true);
166 136
167 // Initially we want to paint the background, but without the hover effect. 137 // Initially we want to paint the background, but without the hover effect.
168 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); 138 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE);
169 hover_background_animator_.SetPaintsBackground(false, 139 hover_background_animator_.SetPaintsBackground(false,
170 internal::BackgroundAnimator::CHANGE_IMMEDIATE); 140 internal::BackgroundAnimator::CHANGE_IMMEDIATE);
171 141
172 tray_container_ = new TrayContainer(shelf_alignment_); 142 tray_container_ = new TrayContainer(shelf_alignment_);
173 SetContents(tray_container_); 143 SetContents(tray_container_);
174 } 144 }
175 145
176 TrayBackgroundView::~TrayBackgroundView() { 146 TrayBackgroundView::~TrayBackgroundView() {
177 GetWidget()->GetNativeView()->layer()->GetAnimator()->RemoveObserver(
178 layer_animation_observer_.get());
179 }
180
181 void TrayBackgroundView::Initialize() {
182 GetWidget()->GetNativeView()->layer()->GetAnimator()->AddObserver(
183 layer_animation_observer_.get());
184 SetBorder();
185 } 147 }
186 148
187 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { 149 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
188 hover_background_animator_.SetPaintsBackground(true, 150 hover_background_animator_.SetPaintsBackground(true,
189 internal::BackgroundAnimator::CHANGE_ANIMATE); 151 internal::BackgroundAnimator::CHANGE_ANIMATE);
190 } 152 }
191 153
192 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { 154 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) {
193 hover_background_animator_.SetPaintsBackground(false, 155 hover_background_animator_.SetPaintsBackground(false,
194 internal::BackgroundAnimator::CHANGE_ANIMATE); 156 internal::BackgroundAnimator::CHANGE_ANIMATE);
195 } 157 }
196 158
197 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { 159 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {
198 PreferredSizeChanged(); 160 PreferredSizeChanged();
199 } 161 }
200 162
201 void TrayBackgroundView::OnPaintFocusBorder(gfx::Canvas* canvas) {
202 // The tray itself expands to the right and bottom edge of the screen to make
203 // sure clicking on the edges brings up the popup. However, the focus border
204 // should be only around the container.
205 if (GetWidget() && GetWidget()->IsActive())
206 DrawBorder(canvas, GetContentsBounds());
207 }
208
209 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
210 // Return focus to the login view. See crbug.com/120500.
211 views::View* v = GetNextFocusableView();
212 if (v)
213 v->AboutToRequestFocusFromTabTraversal(reverse);
214 }
215
216 bool TrayBackgroundView::PerformAction(const ui::Event& event) { 163 bool TrayBackgroundView::PerformAction(const ui::Event& event) {
217 return false; 164 return false;
218 } 165 }
219 166
220 void TrayBackgroundView::UpdateBackground(int alpha) { 167 void TrayBackgroundView::UpdateBackground(int alpha) {
221 if (background_) { 168 if (background_) {
222 background_->set_alpha(hide_background_animator_.alpha() + 169 background_->set_alpha(hide_background_animator_.alpha() +
223 hover_background_animator_.alpha()); 170 hover_background_animator_.alpha());
224 } 171 }
225 SchedulePaint(); 172 SchedulePaint();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } else { 210 } else {
264 set_border(views::Border::CreateEmptyBorder( 211 set_border(views::Border::CreateEmptyBorder(
265 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, 212 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment,
266 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, 213 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0,
267 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); 214 kPaddingFromOuterEdgeOfLauncherVerticalAlignment));
268 } 215 }
269 } 216 }
270 217
271 } // namespace internal 218 } // namespace internal
272 } // namespace ash 219 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_background_view.h ('k') | ash/system/web_notification/web_notification_tray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698