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

Side by Side Diff: ash/wallpaper/wallpaper_view.cc

Issue 2290473004: Rename ash desktop_background to wallpaper. (Closed)
Patch Set: Cleanup Created 4 years, 3 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 "ash/desktop_background/desktop_background_view.h" 5 #include "ash/wallpaper/wallpaper_view.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/display/display_info.h" 8 #include "ash/common/display/display_info.h"
9 #include "ash/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/wallpaper/wallpaper_delegate.h" 10 #include "ash/common/wallpaper/wallpaper_delegate.h"
11 #include "ash/common/wm/overview/window_selector_controller.h" 11 #include "ash/common/wm/overview/window_selector_controller.h"
12 #include "ash/common/wm_lookup.h" 12 #include "ash/common/wm_lookup.h"
13 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
14 #include "ash/desktop_background/desktop_background_controller.h"
15 #include "ash/desktop_background/desktop_background_widget_controller.h"
16 #include "ash/root_window_controller.h" 14 #include "ash/root_window_controller.h"
17 #include "ash/shell.h" 15 #include "ash/shell.h"
16 #include "ash/wallpaper/wallpaper_controller.h"
17 #include "ash/wallpaper/wallpaper_widget_controller.h"
18 #include "ui/display/display.h" 18 #include "ui/display/display.h"
19 #include "ui/display/screen.h" 19 #include "ui/display/screen.h"
20 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/geometry/safe_integer_conversions.h" 21 #include "ui/gfx/geometry/safe_integer_conversions.h"
22 #include "ui/gfx/geometry/size_conversions.h" 22 #include "ui/gfx/geometry/size_conversions.h"
23 #include "ui/gfx/transform.h" 23 #include "ui/gfx/transform.h"
24 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
25 25
26 namespace ash { 26 namespace ash {
27 namespace { 27 namespace {
28 28
29 // A view that controls the child view's layer so that the layer always has the 29 // A view that controls the child view's layer so that the layer always has the
30 // same size as the display's original, un-scaled size in DIP. The layer is then 30 // same size as the display's original, un-scaled size in DIP. The layer is then
31 // transformed to fit to the virtual screen size when laid-out. This is to avoid 31 // transformed to fit to the virtual screen size when laid-out. This is to avoid
32 // scaling the image at painting time, then scaling it back to the screen size 32 // scaling the image at painting time, then scaling it back to the screen size
33 // in the compositor. 33 // in the compositor.
34 class LayerControlView : public views::View { 34 class LayerControlView : public views::View {
35 public: 35 public:
36 explicit LayerControlView(views::View* view) { 36 explicit LayerControlView(views::View* view) {
37 AddChildView(view); 37 AddChildView(view);
38 view->SetPaintToLayer(true); 38 view->SetPaintToLayer(true);
39 } 39 }
40 40
41 // Overrides views::View. 41 // Overrides views::View.
42 void Layout() override { 42 void Layout() override {
43 WmWindow* window = WmLookup::Get()->GetWindowForWidget(GetWidget()); 43 WmWindow* window = WmLookup::Get()->GetWindowForWidget(GetWidget());
44 // Keep |this| at the bottom since there may be other windows on top of the 44 // Keep |this| at the bottom since there may be other windows on top of the
45 // background view such as an overview mode shield. 45 // wallpaper view such as an overview mode shield.
46 window->GetParent()->StackChildAtBottom(window); 46 window->GetParent()->StackChildAtBottom(window);
47 display::Display display = window->GetDisplayNearestWindow(); 47 display::Display display = window->GetDisplayNearestWindow();
48 DisplayInfo info = WmShell::Get()->GetDisplayInfo(display.id()); 48 DisplayInfo info = WmShell::Get()->GetDisplayInfo(display.id());
49 float ui_scale = info.GetEffectiveUIScale(); 49 float ui_scale = info.GetEffectiveUIScale();
50 gfx::Size rounded_size = 50 gfx::Size rounded_size =
51 gfx::ScaleToFlooredSize(display.size(), 1.f / ui_scale); 51 gfx::ScaleToFlooredSize(display.size(), 1.f / ui_scale);
52 DCHECK_EQ(1, child_count()); 52 DCHECK_EQ(1, child_count());
53 views::View* child = child_at(0); 53 views::View* child = child_at(0);
54 child->SetBounds(0, 0, rounded_size.width(), rounded_size.height()); 54 child->SetBounds(0, 0, rounded_size.width(), rounded_size.height());
55 gfx::Transform transform; 55 gfx::Transform transform;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (event->type() == ui::ET_GESTURE_TAP && controller->IsSelecting()) { 94 if (event->type() == ui::ET_GESTURE_TAP && controller->IsSelecting()) {
95 controller->ToggleOverview(); 95 controller->ToggleOverview();
96 event->StopPropagation(); 96 event->StopPropagation();
97 } 97 }
98 } 98 }
99 99
100 DISALLOW_COPY_AND_ASSIGN(PreEventDispatchHandler); 100 DISALLOW_COPY_AND_ASSIGN(PreEventDispatchHandler);
101 }; 101 };
102 102
103 //////////////////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////////////////
104 // DesktopBackgroundView, public: 104 // WallpaperView, public:
105 105
106 DesktopBackgroundView::DesktopBackgroundView() 106 WallpaperView::WallpaperView()
107 : pre_dispatch_handler_(new PreEventDispatchHandler()) { 107 : pre_dispatch_handler_(new PreEventDispatchHandler()) {
108 set_context_menu_controller(this); 108 set_context_menu_controller(this);
109 AddPreTargetHandler(pre_dispatch_handler_.get()); 109 AddPreTargetHandler(pre_dispatch_handler_.get());
110 } 110 }
111 111
112 DesktopBackgroundView::~DesktopBackgroundView() { 112 WallpaperView::~WallpaperView() {
113 RemovePreTargetHandler(pre_dispatch_handler_.get()); 113 RemovePreTargetHandler(pre_dispatch_handler_.get());
114 } 114 }
115 115
116 //////////////////////////////////////////////////////////////////////////////// 116 ////////////////////////////////////////////////////////////////////////////////
117 // DesktopBackgroundView, views::View overrides: 117 // WallpaperView, views::View overrides:
118 118
119 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { 119 void WallpaperView::OnPaint(gfx::Canvas* canvas) {
120 // Scale the image while maintaining the aspect ratio, cropping as 120 // Scale the image while maintaining the aspect ratio, cropping as necessary
121 // necessary to fill the background. Ideally the image should be larger 121 // to fill the wallpaper. Ideally the image should be larger than the largest
122 // than the largest display supported, if not we will scale and center it if 122 // display supported, if not we will scale and center it if the layout is
123 // the layout is wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED. 123 // wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED.
124 DesktopBackgroundController* controller = 124 WallpaperController* controller =
125 Shell::GetInstance()->desktop_background_controller(); 125 Shell::GetInstance()->wallpaper_controller();
126 gfx::ImageSkia wallpaper = controller->GetWallpaper(); 126 gfx::ImageSkia wallpaper = controller->GetWallpaper();
127 wallpaper::WallpaperLayout layout = controller->GetWallpaperLayout(); 127 wallpaper::WallpaperLayout layout = controller->GetWallpaperLayout();
128 128
129 // Wallpapers with png format could be partially transparent. 129 // Wallpapers with png format could be partially transparent. Fill the canvas
130 // Fill the canvas with black background to make it opaque 130 // with black to make it opaque before painting the wallpaper.
131 // before painting wallpaper
132 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); 131 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK);
133 132
134 if (wallpaper.isNull()) 133 if (wallpaper.isNull())
135 return; 134 return;
136 135
137 if (layout == wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED) { 136 if (layout == wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED) {
138 // The dimension with the smallest ratio must be cropped, the other one 137 // The dimension with the smallest ratio must be cropped, the other one
139 // is preserved. Both are set in gfx::Size cropped_size. 138 // is preserved. Both are set in gfx::Size cropped_size.
140 double horizontal_ratio = 139 double horizontal_ratio =
141 static_cast<double>(width()) / static_cast<double>(wallpaper.width()); 140 static_cast<double>(width()) / static_cast<double>(wallpaper.width());
(...skipping 29 matching lines...) Expand all
171 gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale, 170 gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale,
172 wallpaper.height() / image_scale); 171 wallpaper.height() / image_scale);
173 // All other are simply centered, and not scaled (but may be clipped). 172 // All other are simply centered, and not scaled (but may be clipped).
174 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), wallpaper.height(), 173 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), wallpaper.height(),
175 (width() - wallpaper_rect.width()) / 2, 174 (width() - wallpaper_rect.width()) / 2,
176 (height() - wallpaper_rect.height()) / 2, 175 (height() - wallpaper_rect.height()) / 2,
177 wallpaper_rect.width(), wallpaper_rect.height(), true); 176 wallpaper_rect.width(), wallpaper_rect.height(), true);
178 } 177 }
179 } 178 }
180 179
181 bool DesktopBackgroundView::OnMousePressed(const ui::MouseEvent& event) { 180 bool WallpaperView::OnMousePressed(const ui::MouseEvent& event) {
182 return true; 181 return true;
183 } 182 }
184 183
185 void DesktopBackgroundView::ShowContextMenuForView( 184 void WallpaperView::ShowContextMenuForView(views::View* source,
186 views::View* source, 185 const gfx::Point& point,
187 const gfx::Point& point, 186 ui::MenuSourceType source_type) {
188 ui::MenuSourceType source_type) {
189 WmShell::Get()->ShowContextMenu(point, source_type); 187 WmShell::Get()->ShowContextMenu(point, source_type);
190 } 188 }
191 189
192 views::Widget* CreateDesktopBackground(WmWindow* root_window, 190 views::Widget* CreateWallpaper(WmWindow* root_window, int container_id) {
193 int container_id) {
194 aura::Window* aura_root_window = WmWindowAura::GetAuraWindow(root_window); 191 aura::Window* aura_root_window = WmWindowAura::GetAuraWindow(root_window);
195 DesktopBackgroundController* controller = 192 WallpaperController* controller =
196 Shell::GetInstance()->desktop_background_controller(); 193 Shell::GetInstance()->wallpaper_controller();
197 WallpaperDelegate* wallpaper_delegate = WmShell::Get()->wallpaper_delegate(); 194 WallpaperDelegate* wallpaper_delegate = WmShell::Get()->wallpaper_delegate();
198 195
199 views::Widget* desktop_widget = new views::Widget; 196 views::Widget* wallpaper_widget = new views::Widget;
200 views::Widget::InitParams params( 197 views::Widget::InitParams params(
201 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 198 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
202 params.name = "DesktopBackgroundView"; 199 params.name = "WallpaperView";
203 if (controller->GetWallpaper().isNull()) 200 if (controller->GetWallpaper().isNull())
204 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 201 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
205 params.parent = aura_root_window->GetChildById(container_id); 202 params.parent = aura_root_window->GetChildById(container_id);
206 desktop_widget->Init(params); 203 wallpaper_widget->Init(params);
207 desktop_widget->SetContentsView( 204 wallpaper_widget->SetContentsView(new LayerControlView(new WallpaperView()));
208 new LayerControlView(new DesktopBackgroundView()));
209 int animation_type = wallpaper_delegate->GetAnimationType(); 205 int animation_type = wallpaper_delegate->GetAnimationType();
210 WmWindow* desktop_window = 206 WmWindow* wallpaper_window =
211 WmLookup::Get()->GetWindowForWidget(desktop_widget); 207 WmLookup::Get()->GetWindowForWidget(wallpaper_widget);
212 desktop_window->SetVisibilityAnimationType(animation_type); 208 wallpaper_window->SetVisibilityAnimationType(animation_type);
213 209
214 RootWindowController* root_window_controller = 210 RootWindowController* root_window_controller =
215 GetRootWindowController(aura_root_window); 211 GetRootWindowController(aura_root_window);
216 212
217 // Enable wallpaper transition for the following cases: 213 // Enable wallpaper transition for the following cases:
218 // 1. Initial(OOBE) wallpaper animation. 214 // 1. Initial(OOBE) wallpaper animation.
219 // 2. Wallpaper fades in from a non empty background. 215 // 2. Wallpaper fades in from a non empty background.
220 // 3. From an empty background, chrome transit to a logged in user session. 216 // 3. From an empty background, chrome transit to a logged in user session.
221 // 4. From an empty background, guest user logged in. 217 // 4. From an empty background, guest user logged in.
222 if (wallpaper_delegate->ShouldShowInitialAnimation() || 218 if (wallpaper_delegate->ShouldShowInitialAnimation() ||
223 root_window_controller->animating_wallpaper_controller() || 219 root_window_controller->animating_wallpaper_controller() ||
224 WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers()) { 220 WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers()) {
225 desktop_window->SetVisibilityAnimationTransition(::wm::ANIMATE_SHOW); 221 wallpaper_window->SetVisibilityAnimationTransition(::wm::ANIMATE_SHOW);
226 int duration_override = wallpaper_delegate->GetAnimationDurationOverride(); 222 int duration_override = wallpaper_delegate->GetAnimationDurationOverride();
227 if (duration_override) { 223 if (duration_override) {
228 desktop_window->SetVisibilityAnimationDuration( 224 wallpaper_window->SetVisibilityAnimationDuration(
229 base::TimeDelta::FromMilliseconds(duration_override)); 225 base::TimeDelta::FromMilliseconds(duration_override));
230 } 226 }
231 } else { 227 } else {
232 // Disable animation if transition to login screen from an empty background. 228 // Disable animation if transition to login screen from an empty background.
233 desktop_window->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); 229 wallpaper_window->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE);
234 } 230 }
235 231
236 desktop_widget->SetBounds(params.parent->bounds()); 232 wallpaper_widget->SetBounds(params.parent->bounds());
237 return desktop_widget; 233 return wallpaper_widget;
238 } 234 }
239 235
240 } // namespace ash 236 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698