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

Unified Diff: chrome/browser/ui/panels/docked_panel_strip.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/docked_panel_strip.cc
diff --git a/chrome/browser/ui/panels/docked_panel_strip.cc b/chrome/browser/ui/panels/docked_panel_strip.cc
index 40fbb2599e92b3b74cc5e7630a17c0b283e1fa67..8554f5f5f7e9b480abc81ddb2dcb7285029c7578 100644
--- a/chrome/browser/ui/panels/docked_panel_strip.cc
+++ b/chrome/browser/ui/panels/docked_panel_strip.cc
@@ -11,6 +11,7 @@
#include "base/message_loop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/panels/overflow_panel_strip.h"
+#include "chrome/browser/ui/panels/panel_drag_controller.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/panel_mouse_watcher.h"
#include "chrome/common/chrome_notification_types.h"
@@ -59,7 +60,6 @@ DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager)
minimized_panel_count_(0),
are_titlebars_up_(false),
disable_layout_refresh_(false),
- dragging_panel_(NULL),
dragging_panel_original_x_(0),
delayed_titlebar_action_(NO_ACTION),
titlebar_action_factory_(this) {
@@ -67,7 +67,6 @@ DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager)
DockedPanelStrip::~DockedPanelStrip() {
DCHECK(panels_.empty());
- DCHECK(panels_pending_to_remove_.empty());
DCHECK(panels_in_temporary_layout_.empty());
DCHECK_EQ(0, minimized_panel_count_);
}
@@ -183,7 +182,6 @@ void DockedPanelStrip::AddPanel(Panel* panel) {
// Set panel properties for this strip.
panel->SetAppIconVisibility(true);
- panel->set_draggable(!panel->has_temporary_layout());
panel->ApplyVisualStyleForStrip();
if (panel->has_temporary_layout())
@@ -210,79 +208,65 @@ int DockedPanelStrip::GetRightMostAvailablePosition() const {
}
bool DockedPanelStrip::RemovePanel(Panel* panel) {
+ bool refresh_layout = !disable_layout_refresh_;
if (panel->has_temporary_layout()) {
panels_in_temporary_layout_.erase(panel);
- return true;
- }
+ refresh_layout = false;
jennb 2012/02/17 21:28:45 Keep this 'return true'. No need for refresh_layou
jianli 2012/02/17 23:52:56 Per discussion, remove the change from this patch.
+ } else {
+ Panels::iterator iter = find(panels_.begin(), panels_.end(), panel);
+ if (iter == panels_.end())
+ return false;
- if (find(panels_.begin(), panels_.end(), panel) == panels_.end())
- return false;
+ if (panel->expansion_state() != Panel::EXPANDED)
+ DecrementMinimizedPanels();
- // If we're in the process of dragging, delay the removal.
- if (dragging_panel_) {
- panels_pending_to_remove_.push_back(panel);
- return true;
+ panels_.erase(iter);
}
- DoRemove(panel);
+ panel_manager_->OnPanelRemoved(panel);
jennb 2012/02/17 21:28:45 Move this right after erase(iter) so notification
jianli 2012/02/17 23:52:56 Per discussion, remove the change from this patch.
- if (!disable_layout_refresh_)
+ if (refresh_layout)
RefreshLayout();
return true;
}
-void DockedPanelStrip::DelayedRemove() {
- for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i)
- DoRemove(panels_pending_to_remove_[i]);
- panels_pending_to_remove_.clear();
- RefreshLayout();
-}
-
-bool DockedPanelStrip::DoRemove(Panel* panel) {
- Panels::iterator iter = find(panels_.begin(), panels_.end(), panel);
- if (iter == panels_.end())
- return false;
-
- if (panel->expansion_state() != Panel::EXPANDED)
- DecrementMinimizedPanels();
-
- panels_.erase(iter);
- panel_manager_->OnPanelRemoved(panel);
- return true;
+bool DockedPanelStrip::CanDragPanel(Panel* panel) const {
+ // Only the panels having temporary layout can't be dragged.
+ return !panel->has_temporary_layout();
}
-void DockedPanelStrip::StartDragging(Panel* panel) {
+void DockedPanelStrip::StartDraggingPanel(Panel* panel) {
dragging_panel_iterator_ = find(panels_.begin(), panels_.end(), panel);
DCHECK(dragging_panel_iterator_ != panels_.end());
- dragging_panel_ = panel;
dragging_panel_bounds_ = panel->GetBounds();
dragging_panel_original_x_ = dragging_panel_bounds_.x();
}
-void DockedPanelStrip::Drag(int delta_x) {
- DCHECK(dragging_panel_);
-
+void DockedPanelStrip::DragPanel(int delta_x, int delta_y) {
if (!delta_x)
return;
+ Panel* dragging_panel = panel_manager_->drag_controller()->dragging_panel();
+ DCHECK(dragging_panel);
+
// Moves this panel to the dragging position.
- gfx::Rect new_bounds(dragging_panel_->GetBounds());
+ gfx::Rect new_bounds(dragging_panel->GetBounds());
new_bounds.set_x(new_bounds.x() + delta_x);
- dragging_panel_->SetPanelBounds(new_bounds);
+ dragging_panel->SetPanelBounds(new_bounds);
// Checks and processes other affected panels.
if (delta_x > 0)
- DragRight();
+ DragRight(dragging_panel);
else
- DragLeft();
+ DragLeft(dragging_panel);
}
-void DockedPanelStrip::DragLeft() {
+void DockedPanelStrip::DragLeft(Panel* dragging_panel) {
// This is the left corner of the dragging panel. We use it to check against
// all the panels on its left.
- int dragging_panel_left_boundary = dragging_panel_->GetBounds().x();
+ int dragging_panel_left_boundary = dragging_panel->GetBounds().x();
// This is the right corner which a panel will be moved to.
int current_panel_right_boundary =
@@ -308,7 +292,7 @@ void DockedPanelStrip::DragLeft() {
// Swaps current panel and dragging panel.
*dragging_panel_iterator_ = current_panel;
- *current_panel_iterator = dragging_panel_;
+ *current_panel_iterator = dragging_panel;
dragging_panel_iterator_ = current_panel_iterator;
}
@@ -318,11 +302,11 @@ void DockedPanelStrip::DragLeft() {
dragging_panel_bounds_.width());
}
-void DockedPanelStrip::DragRight() {
+void DockedPanelStrip::DragRight(Panel* dragging_panel) {
// This is the right corner of the dragging panel. We use it to check against
// all the panels on its right.
- int dragging_panel_right_boundary = dragging_panel_->GetBounds().x() +
- dragging_panel_->GetBounds().width() - 1;
+ int dragging_panel_right_boundary = dragging_panel->GetBounds().x() +
+ dragging_panel->GetBounds().width() - 1;
// This is the left corner which a panel will be moved to.
int current_panel_left_boundary = dragging_panel_bounds_.x();
@@ -347,7 +331,7 @@ void DockedPanelStrip::DragRight() {
// Swaps current panel and dragging panel.
*dragging_panel_iterator_ = current_panel;
- *current_panel_iterator = dragging_panel_;
+ *current_panel_iterator = dragging_panel;
dragging_panel_iterator_ = current_panel_iterator;
}
@@ -356,17 +340,14 @@ void DockedPanelStrip::DragRight() {
dragging_panel_bounds_.set_x(current_panel_left_boundary);
}
-void DockedPanelStrip::EndDragging(bool cancelled) {
- DCHECK(dragging_panel_);
+void DockedPanelStrip::EndDraggingPanel(bool cancelled) {
+ Panel* dragging_panel = panel_manager_->drag_controller()->dragging_panel();
+ DCHECK(dragging_panel);
if (cancelled)
- Drag(dragging_panel_original_x_ - dragging_panel_->GetBounds().x());
+ DragPanel(dragging_panel_original_x_ - dragging_panel->GetBounds().x(), 0);
else
- dragging_panel_->SetPanelBounds(dragging_panel_bounds_);
-
- dragging_panel_ = NULL;
-
- DelayedRemove();
+ dragging_panel->SetPanelBounds(dragging_panel_bounds_);
}
void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) {
@@ -524,8 +505,12 @@ bool DockedPanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const {
// If the panel is showing titlebar only, we want to keep it up when it is
// being dragged.
- if (state == Panel::TITLE_ONLY && is_dragging_panel())
- return true;
+ if (state == Panel::TITLE_ONLY) {
+ Panel* dragging_panel =
jennb 2012/02/17 21:28:45 shouldn't this be: if (state == title_only && dra
jianli 2012/02/17 23:52:56 Done.
+ panel_manager_->drag_controller()->dragging_panel();
+ if (dragging_panel && dragging_panel->panel_strip() == this)
+ return true;
+ }
// We do not want to bring up other minimized panels if the mouse is over
// the panel that pops up the titlebar to attract attention.
@@ -744,7 +729,6 @@ void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) {
void DockedPanelStrip::CloseAll() {
// This should only be called at the end of tests to clean up.
- DCHECK(!dragging_panel_);
DCHECK(panels_in_temporary_layout_.empty());
// Make a copy of the iterator as closing panels can modify the vector.
@@ -755,7 +739,3 @@ void DockedPanelStrip::CloseAll() {
iter != panels_copy.rend(); ++iter)
(*iter)->Close();
}
-
-bool DockedPanelStrip::is_dragging_panel() const {
- return dragging_panel_ != NULL;
-}

Powered by Google App Engine
This is Rietveld 408576698