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

Unified Diff: chrome/browser/ui/panels/panel_drag_controller.cc

Issue 9403035: Refactor intra-strip panel drags by introducing PanelDragController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedback Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/panels/panel_drag_controller.cc
diff --git a/chrome/browser/ui/panels/panel_drag_controller.cc b/chrome/browser/ui/panels/panel_drag_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a56fce4f9500b6e4c1b01472736daef050c51df9
--- /dev/null
+++ b/chrome/browser/ui/panels/panel_drag_controller.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/panels/panel_drag_controller.h"
+
+#include "base/logging.h"
+#include "chrome/browser/ui/panels/panel.h"
+#include "chrome/browser/ui/panels/panel_strip.h"
+
+PanelDragController::PanelDragController()
+ : dragging_panel_(NULL) {
+}
+
+PanelDragController::~PanelDragController() {
+ DCHECK(panels_pending_to_remove_.empty());
+}
+
+void PanelDragController::StartDragging(Panel* panel) {
+ DCHECK(!dragging_panel_);
jennb 2012/02/17 21:28:45 Also DCHECK panel->panel_strip()->CanDragPanel(pan
jianli 2012/02/17 23:52:56 Done.
+
+ dragging_panel_ = panel;
+ dragging_panel_->panel_strip()->StartDraggingPanel(panel);
+}
+
+void PanelDragController::Drag(int delta_x, int delta_y) {
+ DCHECK(dragging_panel_);
+
+ dragging_panel_->panel_strip()->DragPanel(delta_x, delta_y);
+}
+
+void PanelDragController::EndDragging(bool cancelled) {
+ DCHECK(dragging_panel_);
+
+ dragging_panel_->panel_strip()->EndDraggingPanel(cancelled);
+ dragging_panel_ = NULL;
+
+ DelayedRemove();
+}
+
+bool PanelDragController::CanRemovePanel(Panel* panel) {
+ if (!dragging_panel_)
+ return true;
+
+ // The following panels can't be removed immediately:
+ // 1) The dragging panel no matter which strip it is in.
+ // 2) All docked panels.
+ bool can_remove = (panel != dragging_panel_) &&
jennb 2012/02/17 21:28:45 if (panel == dragging_panel_ || is_a_docked_panel)
jianli 2012/02/17 23:52:56 Done.
+ (panel->panel_strip()->type() != PanelStrip::DOCKED);
+ if (!can_remove)
+ panels_pending_to_remove_.insert(panel);
+
+ return can_remove;
+}
+
+void PanelDragController::DelayedRemove() {
+ for (std::set<Panel*>::const_iterator iter =
+ panels_pending_to_remove_.begin();
+ iter != panels_pending_to_remove_.end(); ++iter) {
+ (*iter)->Close();
jennb 2012/02/17 21:28:45 The existing logic allows Close() while dragging.
jianli 2012/02/17 23:52:56 Per discussion, I remove it from this patch.
+ }
+
+ panels_pending_to_remove_.clear();
+}

Powered by Google App Engine
This is Rietveld 408576698