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

Side by Side Diff: ash/wm/workspace/phantom_window_controller.cc

Issue 10837211: Draw web content area correctly on a phantom window for window dragging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove WindowPainter 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/wm/workspace/phantom_window_controller.h" 5 #include "ash/wm/workspace/phantom_window_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/coordinate_conversion.h" 9 #include "ash/wm/coordinate_conversion.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 10 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 paint.setStrokeWidth(SkIntToScalar(2)); 67 paint.setStrokeWidth(SkIntToScalar(2));
68 canvas->sk_canvas()->drawRoundRect( 68 canvas->sk_canvas()->drawRoundRect(
69 gfx::RectToSkRect(gfx::Rect(x, y, w, h)), SkIntToScalar(kRoundRectSize), 69 gfx::RectToSkRect(gfx::Rect(x, y, w, h)), SkIntToScalar(kRoundRectSize),
70 SkIntToScalar(kRoundRectSize), paint); 70 SkIntToScalar(kRoundRectSize), paint);
71 } 71 }
72 72
73 private: 73 private:
74 DISALLOW_COPY_AND_ASSIGN(EdgePainter); 74 DISALLOW_COPY_AND_ASSIGN(EdgePainter);
75 }; 75 };
76 76
77 // Paints the background of the phantom window for window dragging.
78 class WindowPainter : public views::Painter,
79 public aura::WindowObserver {
80 public:
81 explicit WindowPainter(aura::Window* window)
82 : window_(window) {
83 window_->AddObserver(this);
84 }
85
86 virtual ~WindowPainter() {
87 if (window_)
88 window_->RemoveObserver(this);
89 }
90
91 // views::Painter overrides:
92 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE {
93 // TODO(yusukes): Paint child windows of the |window_| correctly. Current
94 // code does not paint e.g. web content area in the window. crbug.com/141766
95 if (window_ && window_->delegate())
96 window_->delegate()->OnPaint(canvas);
97 }
98
99 private:
100 // aura::WindowObserver overrides:
101 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
102 DCHECK_EQ(window_, window);
103 window_ = NULL;
104 }
105
106 aura::Window* window_;
107
108 DISALLOW_COPY_AND_ASSIGN(WindowPainter);
109 };
110
111 } // namespace 77 } // namespace
112 78
113 PhantomWindowController::PhantomWindowController(aura::Window* window) 79 PhantomWindowController::PhantomWindowController(aura::Window* window)
114 : window_(window), 80 : window_(window),
115 phantom_below_window_(NULL), 81 phantom_below_window_(NULL),
116 phantom_widget_(NULL), 82 phantom_widget_(NULL),
117 style_(STYLE_SHADOW) { 83 style_(STYLE_SHADOW),
84 layer_(NULL) {
118 } 85 }
119 86
120 PhantomWindowController::~PhantomWindowController() { 87 PhantomWindowController::~PhantomWindowController() {
121 Hide(); 88 Hide();
122 } 89 }
123 90
124 void PhantomWindowController::SetDestinationDisplay( 91 void PhantomWindowController::SetDestinationDisplay(
125 const gfx::Display& dst_display) { 92 const gfx::Display& dst_display) {
126 dst_display_ = dst_display; 93 dst_display_ = dst_display;
127 } 94 }
128 95
96 void PhantomWindowController::set_layer(ui::Layer* layer) {
97 // Cannot set a layer after the widget is initialized.
98 DCHECK(!phantom_widget_);
99 layer_ = layer;
100 }
101
129 void PhantomWindowController::Show(const gfx::Rect& bounds) { 102 void PhantomWindowController::Show(const gfx::Rect& bounds) {
103 if (layer_)
104 layer_->SetVisible(true);
130 if (bounds == bounds_) 105 if (bounds == bounds_)
131 return; 106 return;
132 bounds_ = bounds; 107 bounds_ = bounds;
133 if (!phantom_widget_) { 108 if (!phantom_widget_) {
134 // Show the phantom at the bounds of the window. We'll animate to the target 109 // Show the phantom at the bounds of the window. We'll animate to the target
135 // bounds. 110 // bounds.
136 start_bounds_ = window_->GetBoundsInScreen(); 111 start_bounds_ = window_->GetBoundsInScreen();
137 CreatePhantomWidget(start_bounds_); 112 CreatePhantomWidget(start_bounds_);
138 } else { 113 } else {
139 start_bounds_ = phantom_widget_->GetWindowBoundsInScreen(); 114 start_bounds_ = phantom_widget_->GetWindowBoundsInScreen();
140 } 115 }
141 animation_.reset(new ui::SlideAnimation(this)); 116 animation_.reset(new ui::SlideAnimation(this));
142 animation_->Show(); 117 animation_->Show();
143 } 118 }
144 119
145 void PhantomWindowController::SetBounds(const gfx::Rect& bounds) { 120 void PhantomWindowController::SetBounds(const gfx::Rect& bounds) {
146 DCHECK(IsShowing()); 121 DCHECK(IsShowing());
122 if (layer_)
123 layer_->SetVisible(true);
147 animation_.reset(); 124 animation_.reset();
148 bounds_ = bounds; 125 bounds_ = bounds;
149 SetBoundsInternal(bounds); 126 SetBoundsInternal(bounds);
150 } 127 }
151 128
152 void PhantomWindowController::Hide() { 129 void PhantomWindowController::Hide() {
153 if (phantom_widget_) 130 if (phantom_widget_)
154 phantom_widget_->Close(); 131 phantom_widget_->Close();
155 phantom_widget_ = NULL; 132 phantom_widget_ = NULL;
133 if (layer_)
134 layer_->SetVisible(false);
156 } 135 }
157 136
158 bool PhantomWindowController::IsShowing() const { 137 bool PhantomWindowController::IsShowing() const {
159 return phantom_widget_ != NULL; 138 return phantom_widget_ != NULL;
160 } 139 }
161 140
162 void PhantomWindowController::set_style(Style style) { 141 void PhantomWindowController::set_style(Style style) {
163 // Cannot change |style_| after the widget is initialized. 142 // Cannot change |style_| after the widget is initialized.
164 DCHECK(!phantom_widget_); 143 DCHECK(!phantom_widget_);
165 style_ = style; 144 style_ = style;
(...skipping 25 matching lines...) Expand all
191 // launcher button. Put the phantom in the same window as the launcher so that 170 // launcher button. Put the phantom in the same window as the launcher so that
192 // the phantom is visible. 171 // the phantom is visible.
193 params.parent = Shell::GetContainer(wm::GetRootWindowMatching(bounds), 172 params.parent = Shell::GetContainer(wm::GetRootWindowMatching(bounds),
194 kShellWindowId_LauncherContainer); 173 kShellWindowId_LauncherContainer);
195 params.can_activate = false; 174 params.can_activate = false;
196 params.keep_on_top = true; 175 params.keep_on_top = true;
197 phantom_widget_->set_focus_on_creation(false); 176 phantom_widget_->set_focus_on_creation(false);
198 phantom_widget_->Init(params); 177 phantom_widget_->Init(params);
199 phantom_widget_->SetVisibilityChangedAnimationsEnabled(false); 178 phantom_widget_->SetVisibilityChangedAnimationsEnabled(false);
200 phantom_widget_->GetNativeWindow()->SetName("PhantomWindow"); 179 phantom_widget_->GetNativeWindow()->SetName("PhantomWindow");
201 views::View* content_view = new views::View; 180 if (style_ == STYLE_SHADOW) {
202 switch (style_) { 181 views::View* content_view = new views::View;
203 case STYLE_SHADOW: 182 content_view->set_background(
204 content_view->set_background( 183 views::Background::CreateBackgroundPainter(true, new EdgePainter));
205 views::Background::CreateBackgroundPainter(true, new EdgePainter)); 184 phantom_widget_->SetContentsView(content_view);
206 break;
207 case STYLE_WINDOW:
208 content_view->set_background(views::Background::CreateBackgroundPainter(
209 true, new WindowPainter(window_)));
210 break;
211 } 185 }
212 phantom_widget_->SetContentsView(content_view);
213 SetBoundsInternal(bounds); 186 SetBoundsInternal(bounds);
214 if (phantom_below_window_) 187 if (phantom_below_window_)
215 phantom_widget_->StackBelow(phantom_below_window_); 188 phantom_widget_->StackBelow(phantom_below_window_);
216 else 189 else
217 phantom_widget_->StackAbove(window_); 190 phantom_widget_->StackAbove(window_);
218 phantom_widget_->Show(); 191 phantom_widget_->Show();
192
193 if (layer_) {
194 aura::Window* window = phantom_widget_->GetNativeWindow();
195 window->layer()->Add(layer_);
196 window->layer()->StackAtTop(layer_);
197 }
198
219 // Fade the window in. 199 // Fade the window in.
220 ui::Layer* layer = phantom_widget_->GetNativeWindow()->layer(); 200 ui::Layer* layer = phantom_widget_->GetNativeWindow()->layer();
221 layer->SetOpacity(0); 201 layer->SetOpacity(0);
222 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); 202 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator());
223 layer->SetOpacity(1); 203 layer->SetOpacity(1);
224 } 204 }
225 205
226 void PhantomWindowController::SetBoundsInternal(const gfx::Rect& bounds) { 206 void PhantomWindowController::SetBoundsInternal(const gfx::Rect& bounds) {
227 aura::Window* window = phantom_widget_->GetNativeWindow(); 207 aura::Window* window = phantom_widget_->GetNativeWindow();
228 aura::client::ScreenPositionClient* screen_position_client = 208 aura::client::ScreenPositionClient* screen_position_client =
229 aura::client::GetScreenPositionClient(window->GetRootWindow()); 209 aura::client::GetScreenPositionClient(window->GetRootWindow());
230 if (screen_position_client && dst_display_.id() != -1) 210 if (screen_position_client && dst_display_.id() != -1)
231 screen_position_client->SetBounds(window, bounds, dst_display_); 211 screen_position_client->SetBounds(window, bounds, dst_display_);
232 else 212 else
233 phantom_widget_->SetBounds(bounds); 213 phantom_widget_->SetBounds(bounds);
234 } 214 }
235 215
236 } // namespace internal 216 } // namespace internal
237 } // namespace ash 217 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/phantom_window_controller.h ('k') | ash/wm/workspace/workspace_window_resizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698