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 "chrome/browser/ui/panels/docked_panel_strip.h" | 5 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 panel), | 176 panel), |
177 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( | 177 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( |
178 kMoveNewPanelToOverflowDelayMs))); | 178 kMoveNewPanelToOverflowDelayMs))); |
179 } | 179 } |
180 #endif | 180 #endif |
181 panel->Initialize(gfx::Rect(x, y, width, height)); | 181 panel->Initialize(gfx::Rect(x, y, width, height)); |
182 } | 182 } |
183 | 183 |
184 // Set panel properties for this strip. | 184 // Set panel properties for this strip. |
185 panel->SetAppIconVisibility(true); | 185 panel->SetAppIconVisibility(true); |
186 panel->set_draggable(!panel->has_temporary_layout()); | |
187 panel->ApplyVisualStyleForStrip(); | 186 panel->ApplyVisualStyleForStrip(); |
188 | 187 |
189 if (panel->has_temporary_layout()) | 188 if (panel->has_temporary_layout()) |
190 panels_in_temporary_layout_.insert(panel); | 189 panels_in_temporary_layout_.insert(panel); |
191 else | 190 else |
192 panels_.push_back(panel); | 191 panels_.push_back(panel); |
193 } | 192 } |
194 | 193 |
195 int DockedPanelStrip::GetMaxPanelWidth() const { | 194 int DockedPanelStrip::GetMaxPanelWidth() const { |
196 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); | 195 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 return false; | 244 return false; |
246 | 245 |
247 if (panel->expansion_state() != Panel::EXPANDED) | 246 if (panel->expansion_state() != Panel::EXPANDED) |
248 DecrementMinimizedPanels(); | 247 DecrementMinimizedPanels(); |
249 | 248 |
250 panels_.erase(iter); | 249 panels_.erase(iter); |
251 panel_manager_->OnPanelRemoved(panel); | 250 panel_manager_->OnPanelRemoved(panel); |
252 return true; | 251 return true; |
253 } | 252 } |
254 | 253 |
255 void DockedPanelStrip::StartDragging(Panel* panel) { | 254 bool DockedPanelStrip::CanDragPanel(Panel* panel) const { |
| 255 // Only the panels having temporary layout can't be dragged. |
| 256 return !panel->has_temporary_layout(); |
| 257 } |
| 258 |
| 259 void DockedPanelStrip::StartDraggingPanel(Panel* panel) { |
| 260 DCHECK(!dragging_panel_); |
| 261 |
256 dragging_panel_iterator_ = find(panels_.begin(), panels_.end(), panel); | 262 dragging_panel_iterator_ = find(panels_.begin(), panels_.end(), panel); |
257 DCHECK(dragging_panel_iterator_ != panels_.end()); | 263 DCHECK(dragging_panel_iterator_ != panels_.end()); |
258 | 264 |
259 dragging_panel_ = panel; | 265 dragging_panel_ = panel; |
260 dragging_panel_bounds_ = panel->GetBounds(); | 266 dragging_panel_bounds_ = panel->GetBounds(); |
261 dragging_panel_original_x_ = dragging_panel_bounds_.x(); | 267 dragging_panel_original_x_ = dragging_panel_bounds_.x(); |
262 } | 268 } |
263 | 269 |
264 void DockedPanelStrip::Drag(int delta_x) { | 270 void DockedPanelStrip::DragPanel(int delta_x, int delta_y) { |
265 DCHECK(dragging_panel_); | 271 DCHECK(dragging_panel_); |
266 | 272 |
267 if (!delta_x) | 273 if (!delta_x) |
268 return; | 274 return; |
269 | 275 |
270 // Moves this panel to the dragging position. | 276 // Moves this panel to the dragging position. |
271 gfx::Rect new_bounds(dragging_panel_->GetBounds()); | 277 gfx::Rect new_bounds(dragging_panel_->GetBounds()); |
272 new_bounds.set_x(new_bounds.x() + delta_x); | 278 new_bounds.set_x(new_bounds.x() + delta_x); |
273 dragging_panel_->SetPanelBounds(new_bounds); | 279 dragging_panel_->SetPanelBounds(new_bounds); |
274 | 280 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 *dragging_panel_iterator_ = current_panel; | 355 *dragging_panel_iterator_ = current_panel; |
350 *current_panel_iterator = dragging_panel_; | 356 *current_panel_iterator = dragging_panel_; |
351 dragging_panel_iterator_ = current_panel_iterator; | 357 dragging_panel_iterator_ = current_panel_iterator; |
352 } | 358 } |
353 | 359 |
354 // Updates the potential final position of dragging panel as the result of | 360 // Updates the potential final position of dragging panel as the result of |
355 // swapping with panels on its right. | 361 // swapping with panels on its right. |
356 dragging_panel_bounds_.set_x(current_panel_left_boundary); | 362 dragging_panel_bounds_.set_x(current_panel_left_boundary); |
357 } | 363 } |
358 | 364 |
359 void DockedPanelStrip::EndDragging(bool cancelled) { | 365 void DockedPanelStrip::EndDraggingPanel(bool cancelled) { |
360 DCHECK(dragging_panel_); | 366 DCHECK(dragging_panel_); |
361 | 367 |
362 if (cancelled) | 368 if (cancelled) |
363 Drag(dragging_panel_original_x_ - dragging_panel_->GetBounds().x()); | 369 DragPanel(dragging_panel_original_x_ - dragging_panel_->GetBounds().x(), 0); |
364 else | 370 else |
365 dragging_panel_->SetPanelBounds(dragging_panel_bounds_); | 371 dragging_panel_->SetPanelBounds(dragging_panel_bounds_); |
366 | 372 |
367 dragging_panel_ = NULL; | 373 dragging_panel_ = NULL; |
368 | 374 |
369 DelayedRemove(); | 375 DelayedRemove(); |
370 } | 376 } |
371 | 377 |
372 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { | 378 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { |
373 gfx::Size size = panel->restored_size(); | 379 gfx::Size size = panel->restored_size(); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 | 758 |
753 // Start from the bottom to avoid reshuffling. | 759 // Start from the bottom to avoid reshuffling. |
754 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 760 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
755 iter != panels_copy.rend(); ++iter) | 761 iter != panels_copy.rend(); ++iter) |
756 (*iter)->Close(); | 762 (*iter)->Close(); |
757 } | 763 } |
758 | 764 |
759 bool DockedPanelStrip::is_dragging_panel() const { | 765 bool DockedPanelStrip::is_dragging_panel() const { |
760 return dragging_panel_ != NULL; | 766 return dragging_panel_ != NULL; |
761 } | 767 } |
OLD | NEW |