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

Side by Side Diff: ash/wm/panels/panel_window_resizer.cc

Issue 23645008: Use a weak pointer to determine if resizer was destroyed by nested Drag calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/panels/panel_window_resizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/panels/panel_window_resizer.h" 5 #include "ash/wm/panels/panel_window_resizer.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/launcher/launcher.h" 8 #include "ash/launcher/launcher.h"
9 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
10 #include "ash/shelf/shelf_types.h" 10 #include "ash/shelf/shelf_types.h"
11 #include "ash/shelf/shelf_widget.h" 11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
14 #include "ash/wm/coordinate_conversion.h" 14 #include "ash/wm/coordinate_conversion.h"
15 #include "ash/wm/panels/panel_layout_manager.h" 15 #include "ash/wm/panels/panel_layout_manager.h"
16 #include "ash/wm/property_util.h" 16 #include "ash/wm/property_util.h"
17 #include "ash/wm/window_properties.h" 17 #include "ash/wm/window_properties.h"
18 #include "base/memory/weak_ptr.h"
18 #include "ui/aura/client/aura_constants.h" 19 #include "ui/aura/client/aura_constants.h"
19 #include "ui/aura/env.h" 20 #include "ui/aura/env.h"
20 #include "ui/aura/root_window.h" 21 #include "ui/aura/root_window.h"
21 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
22 #include "ui/aura/window_delegate.h" 23 #include "ui/aura/window_delegate.h"
23 #include "ui/base/hit_test.h" 24 #include "ui/base/hit_test.h"
24 #include "ui/base/ui_base_types.h" 25 #include "ui/base/ui_base_types.h"
25 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
26 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
27 28
28 namespace ash { 29 namespace ash {
29 30
30 namespace { 31 namespace {
31 const int kPanelSnapToLauncherDistance = 30; 32 const int kPanelSnapToLauncherDistance = 30;
32 33
33 internal::PanelLayoutManager* GetPanelLayoutManager( 34 internal::PanelLayoutManager* GetPanelLayoutManager(
34 aura::Window* panel_container) { 35 aura::Window* panel_container) {
35 DCHECK(panel_container->id() == internal::kShellWindowId_PanelContainer); 36 DCHECK(panel_container->id() == internal::kShellWindowId_PanelContainer);
36 return static_cast<internal::PanelLayoutManager*>( 37 return static_cast<internal::PanelLayoutManager*>(
37 panel_container->layout_manager()); 38 panel_container->layout_manager());
38 } 39 }
39 40
40 } // namespace 41 } // namespace
41 42
42 PanelWindowResizer::~PanelWindowResizer() { 43 PanelWindowResizer::~PanelWindowResizer() {
43 if (destroyed_)
44 *destroyed_ = true;
45 } 44 }
46 45
47 // static 46 // static
48 PanelWindowResizer* 47 PanelWindowResizer*
49 PanelWindowResizer::Create(WindowResizer* next_window_resizer, 48 PanelWindowResizer::Create(WindowResizer* next_window_resizer,
50 aura::Window* window, 49 aura::Window* window,
51 const gfx::Point& location, 50 const gfx::Point& location,
52 int window_component, 51 int window_component,
53 aura::client::WindowMoveSource source) { 52 aura::client::WindowMoveSource source) {
54 Details details(window, location, window_component, source); 53 Details details(window, location, window_component, source);
55 return details.is_resizable ? 54 return details.is_resizable ?
56 new PanelWindowResizer(next_window_resizer, details) : NULL; 55 new PanelWindowResizer(next_window_resizer, details) : NULL;
57 } 56 }
58 57
59 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { 58 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) {
60 last_location_ = location; 59 last_location_ = location;
61 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); 60 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_);
62 bool destroyed = false;
63 if (!did_move_or_resize_) { 61 if (!did_move_or_resize_) {
64 did_move_or_resize_ = true; 62 did_move_or_resize_ = true;
65 StartedDragging(); 63 StartedDragging();
66 } 64 }
67 65
68 // Check if the destination has changed displays. 66 // Check if the destination has changed displays.
69 gfx::Screen* screen = Shell::GetScreen(); 67 gfx::Screen* screen = Shell::GetScreen();
70 const gfx::Display dst_display = 68 const gfx::Display dst_display =
71 screen->GetDisplayNearestPoint(last_location_); 69 screen->GetDisplayNearestPoint(last_location_);
72 if (dst_display.id() != 70 if (dst_display.id() !=
(...skipping 13 matching lines...) Expand all
86 // The panel's parent already knows that the drag is in progress for this 84 // The panel's parent already knows that the drag is in progress for this
87 // panel. 85 // panel.
88 if (panel_container_ && GetTarget()->parent() != panel_container_) 86 if (panel_container_ && GetTarget()->parent() != panel_container_)
89 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); 87 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget());
90 } 88 }
91 gfx::Point offset; 89 gfx::Point offset;
92 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); 90 gfx::Rect bounds(CalculateBoundsForDrag(details_, location));
93 should_attach_ = AttachToLauncher(bounds, &offset); 91 should_attach_ = AttachToLauncher(bounds, &offset);
94 gfx::Point modified_location(location.x() + offset.x(), 92 gfx::Point modified_location(location.x() + offset.x(),
95 location.y() + offset.y()); 93 location.y() + offset.y());
96 destroyed_ = &destroyed; 94
95 base::WeakPtr<PanelWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
97 next_window_resizer_->Drag(modified_location, event_flags); 96 next_window_resizer_->Drag(modified_location, event_flags);
97 if (!resizer)
98 return;
98 99
99 // TODO(flackr): Refactor the way WindowResizer calls into other window
100 // resizers to avoid the awkward pattern here for checking if
101 // next_window_resizer_ destroys the resizer object.
102 if (destroyed)
103 return;
104 destroyed_ = NULL;
105 if (should_attach_ && 100 if (should_attach_ &&
106 !(details_.bounds_change & WindowResizer::kBoundsChange_Resizes)) { 101 !(details_.bounds_change & WindowResizer::kBoundsChange_Resizes)) {
107 UpdateLauncherPosition(); 102 UpdateLauncherPosition();
108 } 103 }
109 } 104 }
110 105
111 void PanelWindowResizer::CompleteDrag(int event_flags) { 106 void PanelWindowResizer::CompleteDrag(int event_flags) {
112 // The root window can change when dragging into a different screen. 107 // The root window can change when dragging into a different screen.
113 next_window_resizer_->CompleteDrag(event_flags); 108 next_window_resizer_->CompleteDrag(event_flags);
114 FinishDragging(); 109 FinishDragging();
(...skipping 15 matching lines...) Expand all
130 125
131 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, 126 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer,
132 const Details& details) 127 const Details& details)
133 : details_(details), 128 : details_(details),
134 next_window_resizer_(next_window_resizer), 129 next_window_resizer_(next_window_resizer),
135 panel_container_(NULL), 130 panel_container_(NULL),
136 initial_panel_container_(NULL), 131 initial_panel_container_(NULL),
137 did_move_or_resize_(false), 132 did_move_or_resize_(false),
138 was_attached_(GetTarget()->GetProperty(internal::kPanelAttachedKey)), 133 was_attached_(GetTarget()->GetProperty(internal::kPanelAttachedKey)),
139 should_attach_(was_attached_), 134 should_attach_(was_attached_),
140 destroyed_(NULL) { 135 weak_ptr_factory_(this) {
141 DCHECK(details_.is_resizable); 136 DCHECK(details_.is_resizable);
142 panel_container_ = Shell::GetContainer( 137 panel_container_ = Shell::GetContainer(
143 details.window->GetRootWindow(), 138 details.window->GetRootWindow(),
144 internal::kShellWindowId_PanelContainer); 139 internal::kShellWindowId_PanelContainer);
145 initial_panel_container_ = panel_container_; 140 initial_panel_container_ = panel_container_;
146 } 141 }
147 142
148 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, 143 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds,
149 gfx::Point* offset) { 144 gfx::Point* offset) {
150 bool should_attach = false; 145 bool should_attach = false;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 224 }
230 225
231 void PanelWindowResizer::UpdateLauncherPosition() { 226 void PanelWindowResizer::UpdateLauncherPosition() {
232 if (panel_container_) { 227 if (panel_container_) {
233 GetPanelLayoutManager(panel_container_)->launcher()-> 228 GetPanelLayoutManager(panel_container_)->launcher()->
234 UpdateIconPositionForWindow(GetTarget()); 229 UpdateIconPositionForWindow(GetTarget());
235 } 230 }
236 } 231 }
237 232
238 } // namespace aura 233 } // namespace aura
OLDNEW
« no previous file with comments | « ash/wm/panels/panel_window_resizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698