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

Side by Side Diff: ash/drag_drop/drag_drop_controller.cc

Issue 2206033002: mash: Migrate ash::DragImageView to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 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
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ash/drag_drop/drag_drop_controller_unittest.cc » ('j') | 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/drag_drop/drag_drop_controller.h" 5 #include "ash/drag_drop/drag_drop_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/aura/wm_window_aura.h"
10 #include "ash/common/drag_drop/drag_image_view.h"
11 #include "ash/common/wm_shell.h"
9 #include "ash/drag_drop/drag_drop_tracker.h" 12 #include "ash/drag_drop/drag_drop_tracker.h"
10 #include "ash/drag_drop/drag_image_view.h"
11 #include "ash/shell.h" 13 #include "ash/shell.h"
12 #include "base/bind.h" 14 #include "base/bind.h"
13 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
15 #include "base/run_loop.h" 17 #include "base/run_loop.h"
16 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
17 #include "ui/aura/client/capture_client.h" 19 #include "ui/aura/client/capture_client.h"
18 #include "ui/aura/env.h" 20 #include "ui/aura/env.h"
19 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
20 #include "ui/aura/window_delegate.h" 22 #include "ui/aura/window_delegate.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 DragDropController::DragDropController() 129 DragDropController::DragDropController()
128 : drag_data_(NULL), 130 : drag_data_(NULL),
129 drag_operation_(0), 131 drag_operation_(0),
130 drag_window_(NULL), 132 drag_window_(NULL),
131 drag_source_window_(NULL), 133 drag_source_window_(NULL),
132 should_block_during_drag_drop_(true), 134 should_block_during_drag_drop_(true),
133 drag_drop_window_delegate_(new DragDropTrackerDelegate(this)), 135 drag_drop_window_delegate_(new DragDropTrackerDelegate(this)),
134 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE), 136 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE),
135 weak_factory_(this) { 137 weak_factory_(this) {
136 Shell::GetInstance()->PrependPreTargetHandler(this); 138 Shell::GetInstance()->PrependPreTargetHandler(this);
139 WmShell::Get()->AddDisplayObserver(this);
137 } 140 }
138 141
139 DragDropController::~DragDropController() { 142 DragDropController::~DragDropController() {
143 WmShell::Get()->RemoveDisplayObserver(this);
140 Shell::GetInstance()->RemovePreTargetHandler(this); 144 Shell::GetInstance()->RemovePreTargetHandler(this);
141 Cleanup(); 145 Cleanup();
142 if (cancel_animation_) 146 if (cancel_animation_)
143 cancel_animation_->End(); 147 cancel_animation_->End();
144 if (drag_image_) 148 if (drag_image_)
145 drag_image_.reset(); 149 drag_image_.reset();
146 } 150 }
147 151
148 int DragDropController::StartDragAndDrop( 152 int DragDropController::StartDragAndDrop(
149 const ui::OSExchangeData& data, 153 const ui::OSExchangeData& data,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 float drag_image_scale = 1; 196 float drag_image_scale = 1;
193 int drag_image_vertical_offset = 0; 197 int drag_image_vertical_offset = 0;
194 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { 198 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) {
195 drag_image_scale = kTouchDragImageScale; 199 drag_image_scale = kTouchDragImageScale;
196 drag_image_vertical_offset = kTouchDragImageVerticalOffset; 200 drag_image_vertical_offset = kTouchDragImageVerticalOffset;
197 } 201 }
198 gfx::Point start_location = screen_location; 202 gfx::Point start_location = screen_location;
199 drag_image_final_bounds_for_cancel_animation_ = 203 drag_image_final_bounds_for_cancel_animation_ =
200 gfx::Rect(start_location - provider->GetDragImageOffset(), 204 gfx::Rect(start_location - provider->GetDragImageOffset(),
201 provider->GetDragImage().size()); 205 provider->GetDragImage().size());
202 drag_image_.reset(new DragImageView(source_window->GetRootWindow(), source)); 206 drag_image_.reset(new DragImageView(
207 WmWindowAura::Get(source_window->GetRootWindow()), source));
203 drag_image_->SetImage(provider->GetDragImage()); 208 drag_image_->SetImage(provider->GetDragImage());
204 drag_image_offset_ = provider->GetDragImageOffset(); 209 drag_image_offset_ = provider->GetDragImageOffset();
205 gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize()); 210 gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize());
206 drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset( 211 drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset(
207 drag_image_bounds, drag_image_vertical_offset, drag_image_scale, 212 drag_image_bounds, drag_image_vertical_offset, drag_image_scale,
208 &drag_image_offset_); 213 &drag_image_offset_);
209 drag_image_->SetBoundsInScreen(drag_image_bounds); 214 drag_image_->SetBoundsInScreen(drag_image_bounds);
210 drag_image_->SetWidgetVisible(true); 215 drag_image_->SetWidgetVisible(true);
211 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { 216 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) {
212 drag_image_->SetTouchDragOperationHintPosition( 217 drag_image_->SetTouchDragOperationHintPosition(
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 gfx::Rect current_bounds = animation->CurrentValueBetween( 535 gfx::Rect current_bounds = animation->CurrentValueBetween(
531 drag_image_initial_bounds_for_cancel_animation_, 536 drag_image_initial_bounds_for_cancel_animation_,
532 drag_image_final_bounds_for_cancel_animation_); 537 drag_image_final_bounds_for_cancel_animation_);
533 drag_image_->SetBoundsInScreen(current_bounds); 538 drag_image_->SetBoundsInScreen(current_bounds);
534 } 539 }
535 540
536 void DragDropController::AnimationCanceled(const gfx::Animation* animation) { 541 void DragDropController::AnimationCanceled(const gfx::Animation* animation) {
537 AnimationEnded(animation); 542 AnimationEnded(animation);
538 } 543 }
539 544
545 void DragDropController::OnDisplayConfigurationChanging() {
546 // Abort in-progress drags if a monitor is added or removed because the drag
547 // image widget's container may be destroyed.
548 if (IsDragDropInProgress())
549 DragCancel();
550 }
551
540 void DragDropController::StartCanceledAnimation(int animation_duration_ms) { 552 void DragDropController::StartCanceledAnimation(int animation_duration_ms) {
541 DCHECK(drag_image_.get()); 553 DCHECK(drag_image_.get());
542 drag_image_->SetTouchDragOperationHintOff(); 554 drag_image_->SetTouchDragOperationHintOff();
543 drag_image_initial_bounds_for_cancel_animation_ = 555 drag_image_initial_bounds_for_cancel_animation_ =
544 drag_image_->GetBoundsInScreen(); 556 drag_image_->GetBoundsInScreen();
545 cancel_animation_.reset(CreateCancelAnimation( 557 cancel_animation_.reset(CreateCancelAnimation(
546 animation_duration_ms, kCancelAnimationFrameRate, this)); 558 animation_duration_ms, kCancelAnimationFrameRate, this));
547 cancel_animation_->Start(); 559 cancel_animation_->Start();
548 } 560 }
549 561
(...skipping 12 matching lines...) Expand all
562 if (drag_window_) 574 if (drag_window_)
563 drag_window_->RemoveObserver(this); 575 drag_window_->RemoveObserver(this);
564 drag_window_ = NULL; 576 drag_window_ = NULL;
565 drag_data_ = NULL; 577 drag_data_ = NULL;
566 // Cleanup can be called again while deleting DragDropTracker, so delete 578 // Cleanup can be called again while deleting DragDropTracker, so delete
567 // the pointer with a local variable to avoid double free. 579 // the pointer with a local variable to avoid double free.
568 std::unique_ptr<ash::DragDropTracker> holder = std::move(drag_drop_tracker_); 580 std::unique_ptr<ash::DragDropTracker> holder = std::move(drag_drop_tracker_);
569 } 581 }
570 582
571 } // namespace ash 583 } // namespace ash
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ash/drag_drop/drag_drop_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698