| OLD | NEW |
| 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/drag_window_controller.h" | 5 #include "ash/wm/drag_window_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/display/window_tree_host_manager.h" | 9 #include "ash/display/window_tree_host_manager.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
| 15 #include "ui/aura/client/screen_position_client.h" | 16 #include "ui/aura/client/screen_position_client.h" |
| 16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
| 18 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
| 19 #include "ui/base/hit_test.h" | 20 #include "ui/base/hit_test.h" |
| 20 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 21 #include "ui/compositor/layer_tree_owner.h" | 22 #include "ui/compositor/layer_tree_owner.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 void OnWindowDestroying(aura::Window* window) override { | 156 void OnWindowDestroying(aura::Window* window) override { |
| 156 DCHECK_EQ(drag_window_, window); | 157 DCHECK_EQ(drag_window_, window); |
| 157 drag_window_ = nullptr; | 158 drag_window_ = nullptr; |
| 158 } | 159 } |
| 159 | 160 |
| 160 aura::Window* root_window_; | 161 aura::Window* root_window_; |
| 161 | 162 |
| 162 aura::Window* drag_window_ = nullptr; // Owned by the container. | 163 aura::Window* drag_window_ = nullptr; // Owned by the container. |
| 163 | 164 |
| 164 // The copy of window_->layer() and its descendants. | 165 // The copy of window_->layer() and its descendants. |
| 165 scoped_ptr<ui::LayerTreeOwner> layer_owner_; | 166 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; |
| 166 | 167 |
| 167 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); | 168 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); |
| 168 }; | 169 }; |
| 169 | 170 |
| 170 // static | 171 // static |
| 171 float DragWindowController::GetDragWindowOpacity( | 172 float DragWindowController::GetDragWindowOpacity( |
| 172 const gfx::Rect& window_bounds, | 173 const gfx::Rect& window_bounds, |
| 173 const gfx::Rect& visible_bounds) { | 174 const gfx::Rect& visible_bounds) { |
| 174 // The maximum opacity of the drag phantom window. | 175 // The maximum opacity of the drag phantom window. |
| 175 static const float kMaxOpacity = 0.8f; | 176 static const float kMaxOpacity = 0.8f; |
| 176 | 177 |
| 177 return kMaxOpacity * visible_bounds.size().GetArea() / | 178 return kMaxOpacity * visible_bounds.size().GetArea() / |
| 178 window_bounds.size().GetArea(); | 179 window_bounds.size().GetArea(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 DragWindowController::DragWindowController(aura::Window* window) | 182 DragWindowController::DragWindowController(aura::Window* window) |
| 182 : window_(window) { | 183 : window_(window) { |
| 183 DCHECK(drag_windows_.empty()); | 184 DCHECK(drag_windows_.empty()); |
| 184 gfx::Screen* screen = gfx::Screen::GetScreen(); | 185 gfx::Screen* screen = gfx::Screen::GetScreen(); |
| 185 gfx::Display current = screen->GetDisplayNearestWindow(window_); | 186 gfx::Display current = screen->GetDisplayNearestWindow(window_); |
| 186 | 187 |
| 187 for (const gfx::Display& display : screen->GetAllDisplays()) { | 188 for (const gfx::Display& display : screen->GetAllDisplays()) { |
| 188 if (current.id() == display.id()) | 189 if (current.id() == display.id()) |
| 189 continue; | 190 continue; |
| 190 drag_windows_.push_back( | 191 drag_windows_.push_back( |
| 191 make_scoped_ptr(new DragWindowDetails(display, window_))); | 192 base::WrapUnique(new DragWindowDetails(display, window_))); |
| 192 } | 193 } |
| 193 } | 194 } |
| 194 | 195 |
| 195 DragWindowController::~DragWindowController() {} | 196 DragWindowController::~DragWindowController() {} |
| 196 | 197 |
| 197 void DragWindowController::Update(const gfx::Rect& bounds_in_screen, | 198 void DragWindowController::Update(const gfx::Rect& bounds_in_screen, |
| 198 const gfx::Point& drag_location_in_screen) { | 199 const gfx::Point& drag_location_in_screen) { |
| 199 for (scoped_ptr<DragWindowDetails>& details : drag_windows_) | 200 for (std::unique_ptr<DragWindowDetails>& details : drag_windows_) |
| 200 details->Update(window_, bounds_in_screen, drag_location_in_screen); | 201 details->Update(window_, bounds_in_screen, drag_location_in_screen); |
| 201 } | 202 } |
| 202 | 203 |
| 203 int DragWindowController::GetDragWindowsCountForTest() const { | 204 int DragWindowController::GetDragWindowsCountForTest() const { |
| 204 int count = 0; | 205 int count = 0; |
| 205 for (const scoped_ptr<DragWindowDetails>& details : drag_windows_) { | 206 for (const std::unique_ptr<DragWindowDetails>& details : drag_windows_) { |
| 206 if (details->drag_window_) | 207 if (details->drag_window_) |
| 207 count++; | 208 count++; |
| 208 } | 209 } |
| 209 return count; | 210 return count; |
| 210 } | 211 } |
| 211 | 212 |
| 212 const aura::Window* DragWindowController::GetDragWindowForTest( | 213 const aura::Window* DragWindowController::GetDragWindowForTest( |
| 213 size_t index) const { | 214 size_t index) const { |
| 214 for (const scoped_ptr<DragWindowDetails>& details : drag_windows_) { | 215 for (const std::unique_ptr<DragWindowDetails>& details : drag_windows_) { |
| 215 if (details->drag_window_) { | 216 if (details->drag_window_) { |
| 216 if (index == 0) | 217 if (index == 0) |
| 217 return details->drag_window_; | 218 return details->drag_window_; |
| 218 index--; | 219 index--; |
| 219 } | 220 } |
| 220 } | 221 } |
| 221 return nullptr; | 222 return nullptr; |
| 222 } | 223 } |
| 223 | 224 |
| 224 const ui::LayerTreeOwner* DragWindowController::GetDragLayerOwnerForTest( | 225 const ui::LayerTreeOwner* DragWindowController::GetDragLayerOwnerForTest( |
| 225 size_t index) const { | 226 size_t index) const { |
| 226 for (const scoped_ptr<DragWindowDetails>& details : drag_windows_) { | 227 for (const std::unique_ptr<DragWindowDetails>& details : drag_windows_) { |
| 227 if (details->layer_owner_) { | 228 if (details->layer_owner_) { |
| 228 if (index == 0) | 229 if (index == 0) |
| 229 return details->layer_owner_.get(); | 230 return details->layer_owner_.get(); |
| 230 index--; | 231 index--; |
| 231 } | 232 } |
| 232 } | 233 } |
| 233 return nullptr; | 234 return nullptr; |
| 234 } | 235 } |
| 235 | 236 |
| 236 } // namespace ash | 237 } // namespace ash |
| OLD | NEW |