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

Side by Side Diff: ash/wm/drag_window_controller.cc

Issue 11280283: Extract the code of showing a dragging window on another display from PhantomWindowController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
« no previous file with comments | « ash/wm/drag_window_controller.h ('k') | ash/wm/gestures/system_pinch_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/drag_window_controller.h"
6
7 #include "ash/shell_window_ids.h"
8 #include "ash/wm/window_util.h"
9 #include "ui/aura/client/screen_position_client.h"
10 #include "ui/aura/window.h"
11 #include "ui/compositor/layer.h"
12 #include "ui/compositor/scoped_layer_animation_settings.h"
13 #include "ui/views/corewm/shadow_types.h"
14 #include "ui/views/corewm/window_util.h"
15 #include "ui/views/view.h"
16 #include "ui/views/widget/widget.h"
17
18 namespace ash {
19 namespace internal {
20
21 DragWindowController::DragWindowController(aura::Window* window)
22 : window_(window),
23 drag_widget_(NULL),
24 layer_(NULL) {
25 }
26
27 DragWindowController::~DragWindowController() {
28 Hide();
29 }
30
31 void DragWindowController::SetDestinationDisplay(
32 const gfx::Display& dst_display) {
33 dst_display_ = dst_display;
34 }
35
36 void DragWindowController::Show() {
37 if (!drag_widget_)
38 CreateDragWidget(window_->GetBoundsInScreen());
39 drag_widget_->Show();
40 }
41
42 void DragWindowController::SetBounds(const gfx::Rect& bounds) {
43 DCHECK(drag_widget_);
44 bounds_ = bounds;
45 SetBoundsInternal(bounds);
46 }
47
48 void DragWindowController::Hide() {
49 if (drag_widget_)
50 drag_widget_->Close();
51 drag_widget_ = NULL;
52 if (layer_)
53 views::corewm::DeepDeleteLayers(layer_);
sky 2012/12/04 15:50:37 NULL out layer_ after you do this.
mazda 2012/12/04 17:22:48 Done.
54 }
55
56 void DragWindowController::SetOpacity(float opacity) {
57 DCHECK(drag_widget_);
58 ui::Layer* layer = drag_widget_->GetNativeWindow()->layer();
59 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator());
60 layer->SetOpacity(opacity);
61 }
62
63 void DragWindowController::CreateDragWidget(const gfx::Rect& bounds) {
64 DCHECK(!drag_widget_);
65 drag_widget_ = new views::Widget;
66 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
67 params.transparent = true;
68 params.parent = window_->parent();
69 params.can_activate = false;
70 params.keep_on_top = true;
71 drag_widget_->set_focus_on_creation(false);
72 drag_widget_->Init(params);
73 drag_widget_->SetVisibilityChangedAnimationsEnabled(false);
74 drag_widget_->GetNativeWindow()->SetName("DragWindow");
75 drag_widget_->GetNativeWindow()->set_id(kShellWindowId_PhantomWindow);
76 // Show shadow for the dragging window.
77 SetShadowType(drag_widget_->GetNativeWindow(),
78 views::corewm::SHADOW_TYPE_RECTANGULAR);
79 SetBoundsInternal(bounds);
80 drag_widget_->StackAbove(window_);
81
82 RecreateWindowLayers();
83 aura::Window* window = drag_widget_->GetNativeWindow();
84 layer_->SetVisible(true);
85 window->layer()->Add(layer_);
86 window->layer()->StackAtTop(layer_);
87
88 // Show the widget after all the setups.
89 drag_widget_->Show();
90
91 // Fade the window in.
92 ui::Layer* widget_layer = drag_widget_->GetNativeWindow()->layer();
93 widget_layer->SetOpacity(0);
94 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator());
95 widget_layer->SetOpacity(1);
96 }
97
98 void DragWindowController::SetBoundsInternal(const gfx::Rect& bounds) {
99 aura::Window* window = drag_widget_->GetNativeWindow();
100 aura::client::ScreenPositionClient* screen_position_client =
101 aura::client::GetScreenPositionClient(window->GetRootWindow());
102 if (screen_position_client && dst_display_.is_valid())
103 screen_position_client->SetBounds(window, bounds, dst_display_);
104 else
105 drag_widget_->SetBounds(bounds);
106 }
107
108 void DragWindowController::RecreateWindowLayers() {
109 DCHECK(!layer_);
110 layer_ = views::corewm::RecreateWindowLayers(window_, true);
111 layer_->set_delegate(window_->layer()->delegate());
112 // Place the layer at (0, 0) of the DragWindowController's window.
113 gfx::Rect layer_bounds = layer_->bounds();
114 layer_bounds.set_origin(gfx::Point(0, 0));
115 layer_->SetBounds(layer_bounds);
116 layer_->SetVisible(false);
117 // Detach it from the current container.
118 layer_->parent()->Remove(layer_);
119 }
120
121 } // namespace internal
122 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/drag_window_controller.h ('k') | ash/wm/gestures/system_pinch_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698