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

Side by Side Diff: chrome/browser/ui/panels/docked_panel_strip.cc

Issue 9353002: Created new PanelStrip base class and make DockedPanelStrip and OverflowPanelStrip its subclasses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added the new files - d'oh! 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 unified diff | Download patch | Annotate | Revision Log
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 "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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #else 50 #else
51 const int kDelayBeforeCollapsingFromTitleOnlyStateMs = 0; 51 const int kDelayBeforeCollapsingFromTitleOnlyStateMs = 0;
52 #endif 52 #endif
53 } // namespace 53 } // namespace
54 54
55 // static 55 // static
56 const int DockedPanelStrip::kPanelMinWidth = 100; 56 const int DockedPanelStrip::kPanelMinWidth = 100;
57 const int DockedPanelStrip::kPanelMinHeight = 20; 57 const int DockedPanelStrip::kPanelMinHeight = 20;
58 58
59 DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager) 59 DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager)
60 : panel_manager_(panel_manager), 60 : PanelStrip(PanelStrip::DOCKED),
61 panel_manager_(panel_manager),
61 minimized_panel_count_(0), 62 minimized_panel_count_(0),
62 are_titlebars_up_(false), 63 are_titlebars_up_(false),
63 dragging_panel_index_(kInvalidPanelIndex), 64 dragging_panel_index_(kInvalidPanelIndex),
64 dragging_panel_original_x_(0), 65 dragging_panel_original_x_(0),
65 delayed_titlebar_action_(NO_ACTION), 66 delayed_titlebar_action_(NO_ACTION),
66 titlebar_action_factory_(this) { 67 titlebar_action_factory_(this) {
67 } 68 }
68 69
69 DockedPanelStrip::~DockedPanelStrip() { 70 DockedPanelStrip::~DockedPanelStrip() {
70 DCHECK(panels_.empty()); 71 DCHECK(panels_.empty());
71 DCHECK(panels_pending_to_remove_.empty()); 72 DCHECK(panels_pending_to_remove_.empty());
72 DCHECK(panels_in_temporary_layout_.empty()); 73 DCHECK(panels_in_temporary_layout_.empty());
73 DCHECK_EQ(0, minimized_panel_count_); 74 DCHECK_EQ(0, minimized_panel_count_);
74 } 75 }
75 76
76 void DockedPanelStrip::SetDisplayArea(const gfx::Rect& new_area) { 77 void DockedPanelStrip::SetDisplayArea(const gfx::Rect& display_area) {
77 if (display_area_ == new_area) 78 if (display_area_ == display_area)
78 return; 79 return;
79 80
80 gfx::Rect old_area = display_area_; 81 gfx::Rect old_area = display_area_;
81 display_area_ = new_area; 82 display_area_ = display_area;
82 83
83 if (panels_.empty()) 84 if (panels_.empty())
84 return; 85 return;
85 86
86 Rearrange(); 87 RefreshLayout();
87 } 88 }
88 89
89 void DockedPanelStrip::AddPanel(Panel* panel) { 90 void DockedPanelStrip::AddPanel(Panel* panel) {
90 DCHECK_NE(Panel::IN_OVERFLOW, panel->expansion_state()); 91 DCHECK_NE(Panel::IN_OVERFLOW, panel->expansion_state());
91 92
92 // Always update limits, even for exiting panels, in case the maximums changed 93 // Always update limits, even for exiting panels, in case the maximums changed
93 // while panel was out of the strip. 94 // while panel was out of the strip.
94 int max_panel_width = GetMaxPanelWidth(); 95 int max_panel_width = GetMaxPanelWidth();
95 int max_panel_height = GetMaxPanelHeight(); 96 int max_panel_height = GetMaxPanelHeight();
96 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), 97 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 174
174 int DockedPanelStrip::StartingRightPosition() const { 175 int DockedPanelStrip::StartingRightPosition() const {
175 return display_area_.right(); 176 return display_area_.right();
176 } 177 }
177 178
178 int DockedPanelStrip::GetRightMostAvailablePosition() const { 179 int DockedPanelStrip::GetRightMostAvailablePosition() const {
179 return panels_.empty() ? StartingRightPosition() : 180 return panels_.empty() ? StartingRightPosition() :
180 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); 181 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing);
181 } 182 }
182 183
183 bool DockedPanelStrip::Remove(Panel* panel) { 184 bool DockedPanelStrip::RemovePanel(Panel* panel) {
184 if (panel->has_temporary_layout()) { 185 if (panel->has_temporary_layout()) {
185 panels_in_temporary_layout_.erase(panel); 186 panels_in_temporary_layout_.erase(panel);
186 return true; 187 return true;
187 } 188 }
188 189
189 if (find(panels_.begin(), panels_.end(), panel) == panels_.end()) 190 if (find(panels_.begin(), panels_.end(), panel) == panels_.end())
190 return false; 191 return false;
191 192
192 // If we're in the process of dragging, delay the removal. 193 // If we're in the process of dragging, delay the removal.
193 if (dragging_panel_index_ != kInvalidPanelIndex) { 194 if (dragging_panel_index_ != kInvalidPanelIndex) {
194 panels_pending_to_remove_.push_back(panel); 195 panels_pending_to_remove_.push_back(panel);
195 return true; 196 return true;
196 } 197 }
197 198
198 DoRemove(panel); 199 DoRemove(panel);
199 200
200 // Don't rearrange the strip if a panel is being moved from the panel strip 201 // Don't rearrange the strip if a panel is being moved from the panel strip
201 // to the overflow strip. 202 // to the overflow strip.
202 if (panel->expansion_state() != Panel::IN_OVERFLOW) 203 if (panel->expansion_state() != Panel::IN_OVERFLOW)
203 Rearrange(); 204 RefreshLayout();
204 205
205 return true; 206 return true;
206 } 207 }
207 208
208 void DockedPanelStrip::DelayedRemove() { 209 void DockedPanelStrip::DelayedRemove() {
209 for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i) 210 for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i)
210 DoRemove(panels_pending_to_remove_[i]); 211 DoRemove(panels_pending_to_remove_[i]);
211 panels_pending_to_remove_.clear(); 212 panels_pending_to_remove_.clear();
212 Rearrange(); 213 RefreshLayout();
213 } 214 }
214 215
215 bool DockedPanelStrip::DoRemove(Panel* panel) { 216 bool DockedPanelStrip::DoRemove(Panel* panel) {
216 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); 217 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel);
217 if (iter == panels_.end()) 218 if (iter == panels_.end())
218 return false; 219 return false;
219 220
220 if (panel->expansion_state() == Panel::TITLE_ONLY || 221 if (panel->expansion_state() == Panel::TITLE_ONLY ||
221 panel->expansion_state() == Panel::MINIMIZED) 222 panel->expansion_state() == Panel::MINIMIZED)
222 DecrementMinimizedPanels(); 223 DecrementMinimizedPanels();
223 224
224 panels_.erase(iter); 225 panels_.erase(iter);
225 panel_manager_->OnPanelRemoved(panel); 226 panel_manager_->OnPanelRemoved(panel);
226 return true; 227 return true;
227 } 228 }
228 229
229 void DockedPanelStrip::StartDragging(Panel* panel) { 230 void DockedPanelStrip::StartDragging(Panel* panel) {
230 for (size_t i = 0; i < panels_.size(); ++i) { 231 for (size_t i = 0; i < panels_.size(); ++i) {
231 if (panels_[i] == panel) { 232 if (panels_[i] == panel) {
232 dragging_panel_index_ = i; 233 dragging_panel_index_ = i;
233 dragging_panel_bounds_ = panel->GetBounds(); 234 dragging_panel_bounds_ = panel->GetBounds();
234 dragging_panel_original_x_ = dragging_panel_bounds_.x(); 235 dragging_panel_original_x_ = dragging_panel_bounds_.x();
235 break; 236 break;
236 } 237 }
237 } 238 }
238 } 239 }
239 240
240 void DockedPanelStrip::Drag(int delta_x) { 241 void DockedPanelStrip::Drag(int delta_x, int delta_y) {
241 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); 242 DCHECK(dragging_panel_index_ != kInvalidPanelIndex);
242 243
243 if (!delta_x) 244 if (!delta_x)
244 return; 245 return;
245 246
246 // Moves this panel to the dragging position. 247 // Moves this panel to the dragging position.
247 Panel* dragging_panel = panels_[dragging_panel_index_]; 248 Panel* dragging_panel = panels_[dragging_panel_index_];
248 gfx::Rect new_bounds(dragging_panel->GetBounds()); 249 gfx::Rect new_bounds(dragging_panel->GetBounds());
249 new_bounds.set_x(new_bounds.x() + delta_x); 250 new_bounds.set_x(new_bounds.x() + delta_x);
250 dragging_panel->SetPanelBounds(new_bounds); 251 dragging_panel->SetPanelBounds(new_bounds);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 dragging_panel_index_ = current_panel_index + 1; 340 dragging_panel_index_ = current_panel_index + 1;
340 panels_[dragging_panel_index_] = dragging_panel; 341 panels_[dragging_panel_index_] = dragging_panel;
341 } 342 }
342 } 343 }
343 344
344 void DockedPanelStrip::EndDragging(bool cancelled) { 345 void DockedPanelStrip::EndDragging(bool cancelled) {
345 DCHECK(dragging_panel_index_ != kInvalidPanelIndex); 346 DCHECK(dragging_panel_index_ != kInvalidPanelIndex);
346 347
347 if (cancelled) { 348 if (cancelled) {
348 Drag(dragging_panel_original_x_ - 349 Drag(dragging_panel_original_x_ -
349 panels_[dragging_panel_index_]->GetBounds().x()); 350 panels_[dragging_panel_index_]->GetBounds().x(),
351 0); // TODO(jennb): pass delta_y
350 } else { 352 } else {
351 panels_[dragging_panel_index_]->SetPanelBounds( 353 panels_[dragging_panel_index_]->SetPanelBounds(
352 dragging_panel_bounds_); 354 dragging_panel_bounds_);
353 } 355 }
354 356
355 dragging_panel_index_ = kInvalidPanelIndex; 357 dragging_panel_index_ = kInvalidPanelIndex;
356 358
357 DelayedRemove(); 359 DelayedRemove();
358 } 360 }
359 361
360 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { 362 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) {
361 gfx::Size size = panel->restored_size(); 363 gfx::Size size = panel->restored_size();
362 Panel::ExpansionState expansion_state = panel->expansion_state(); 364 Panel::ExpansionState expansion_state = panel->expansion_state();
363 Panel::ExpansionState old_state = panel->old_expansion_state(); 365 Panel::ExpansionState old_state = panel->old_expansion_state();
364 if (old_state == Panel::IN_OVERFLOW) { 366 if (old_state == Panel::IN_OVERFLOW) {
365 panel_manager_->overflow_strip()->Remove(panel); 367 panel_manager_->overflow_strip()->RemovePanel(panel);
366 AddPanel(panel); 368 AddPanel(panel);
367 panel->SetAppIconVisibility(true); 369 panel->SetAppIconVisibility(true);
368 panel->set_draggable(true); 370 panel->set_draggable(true);
369 } 371 }
370 switch (expansion_state) { 372 switch (expansion_state) {
371 case Panel::EXPANDED: 373 case Panel::EXPANDED:
372 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) 374 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED)
373 DecrementMinimizedPanels(); 375 DecrementMinimizedPanels();
374 break; 376 break;
375 case Panel::TITLE_ONLY: 377 case Panel::TITLE_ONLY:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 DCHECK_LE(minimized_panel_count_, num_panels()); 421 DCHECK_LE(minimized_panel_count_, num_panels());
420 } 422 }
421 423
422 void DockedPanelStrip::DecrementMinimizedPanels() { 424 void DockedPanelStrip::DecrementMinimizedPanels() {
423 minimized_panel_count_--; 425 minimized_panel_count_--;
424 DCHECK_GE(minimized_panel_count_, 0); 426 DCHECK_GE(minimized_panel_count_, 0);
425 if (minimized_panel_count_ == 0) 427 if (minimized_panel_count_ == 0)
426 panel_manager_->mouse_watcher()->RemoveObserver(this); 428 panel_manager_->mouse_watcher()->RemoveObserver(this);
427 } 429 }
428 430
429 void DockedPanelStrip::OnWindowSizeChanged( 431 void DockedPanelStrip::ResizePanelWindow(
430 Panel* panel, const gfx::Size& preferred_window_size) { 432 Panel* panel, const gfx::Size& preferred_window_size) {
431 // The panel width: 433 // The panel width:
432 // * cannot grow or shrink to go beyond [min_width, max_width] 434 // * cannot grow or shrink to go beyond [min_width, max_width]
433 int new_width = preferred_window_size.width(); 435 int new_width = preferred_window_size.width();
434 if (new_width > panel->max_size().width()) 436 if (new_width > panel->max_size().width())
435 new_width = panel->max_size().width(); 437 new_width = panel->max_size().width();
436 if (new_width < panel->min_size().width()) 438 if (new_width < panel->min_size().width())
437 new_width = panel->min_size().width(); 439 new_width = panel->min_size().width();
438 440
439 // The panel height: 441 // The panel height:
(...skipping 23 matching lines...) Expand all
463 if (delta_x != 0 && expansion_state != Panel::IN_OVERFLOW) { 465 if (delta_x != 0 && expansion_state != Panel::IN_OVERFLOW) {
464 bounds.set_width(new_width); 466 bounds.set_width(new_width);
465 bounds.set_x(bounds.x() + delta_x); 467 bounds.set_x(bounds.x() + delta_x);
466 } 468 }
467 469
468 if (bounds != panel->GetBounds()) 470 if (bounds != panel->GetBounds())
469 panel->SetPanelBounds(bounds); 471 panel->SetPanelBounds(bounds);
470 472
471 // Only need to rearrange if panel's width changed. 473 // Only need to rearrange if panel's width changed.
472 if (delta_x != 0) 474 if (delta_x != 0)
473 Rearrange(); 475 RefreshLayout();
474 } 476 }
475 477
476 bool DockedPanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { 478 bool DockedPanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const {
477 // We should always bring up the titlebar if the mouse is over the 479 // We should always bring up the titlebar if the mouse is over the
478 // visible auto-hiding bottom bar. 480 // visible auto-hiding bottom bar.
479 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); 481 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar();
480 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && 482 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) &&
481 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == 483 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) ==
482 AutoHidingDesktopBar::VISIBLE && 484 AutoHidingDesktopBar::VISIBLE &&
483 mouse_y >= display_area_.bottom()) 485 mouse_y >= display_area_.bottom())
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 637
636 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); 638 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP);
637 delayed_titlebar_action_ = NO_ACTION; 639 delayed_titlebar_action_ = NO_ACTION;
638 } 640 }
639 641
640 void DockedPanelStrip::OnFullScreenModeChanged(bool is_full_screen) { 642 void DockedPanelStrip::OnFullScreenModeChanged(bool is_full_screen) {
641 for (size_t i = 0; i < panels_.size(); ++i) 643 for (size_t i = 0; i < panels_.size(); ++i)
642 panels_[i]->FullScreenModeChanged(is_full_screen); 644 panels_[i]->FullScreenModeChanged(is_full_screen);
643 } 645 }
644 646
645 void DockedPanelStrip::Rearrange() { 647 void DockedPanelStrip::RefreshLayout() {
646 int rightmost_position = StartingRightPosition(); 648 int rightmost_position = StartingRightPosition();
647 649
648 size_t panel_index = 0; 650 size_t panel_index = 0;
649 for (; panel_index < panels_.size(); ++panel_index) { 651 for (; panel_index < panels_.size(); ++panel_index) {
650 Panel* panel = panels_[panel_index]; 652 Panel* panel = panels_[panel_index];
651 gfx::Rect new_bounds(panel->GetBounds()); 653 gfx::Rect new_bounds(panel->GetBounds());
652 int x = rightmost_position - new_bounds.width(); 654 int x = rightmost_position - new_bounds.width();
653 655
654 // TODO(jianli): remove the guard when overflow support is enabled on other 656 // TODO(jianli): remove the guard when overflow support is enabled on other
655 // platforms. http://crbug.com/105073 657 // platforms. http://crbug.com/105073
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 #endif 700 #endif
699 } 701 }
700 702
701 void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) { 703 void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) {
702 if (panels_in_temporary_layout_.erase(panel)) { 704 if (panels_in_temporary_layout_.erase(panel)) {
703 DCHECK(panel->has_temporary_layout()); 705 DCHECK(panel->has_temporary_layout());
704 panel->SetExpansionState(Panel::IN_OVERFLOW); 706 panel->SetExpansionState(Panel::IN_OVERFLOW);
705 } 707 }
706 } 708 }
707 709
708 void DockedPanelStrip::RemoveAll() { 710 void DockedPanelStrip::CloseAll() {
709 // This should only be called at the end of tests to clean up. 711 // This should only be called at the end of tests to clean up.
710 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); 712 DCHECK(dragging_panel_index_ == kInvalidPanelIndex);
711 DCHECK(panels_in_temporary_layout_.empty()); 713 DCHECK(panels_in_temporary_layout_.empty());
712 714
713 // Make a copy of the iterator as closing panels can modify the vector. 715 // Make a copy of the iterator as closing panels can modify the vector.
714 Panels panels_copy = panels_; 716 Panels panels_copy = panels_;
715 717
716 // Start from the bottom to avoid reshuffling. 718 // Start from the bottom to avoid reshuffling.
717 for (Panels::reverse_iterator iter = panels_copy.rbegin(); 719 for (Panels::reverse_iterator iter = panels_copy.rbegin();
718 iter != panels_copy.rend(); ++iter) 720 iter != panels_copy.rend(); ++iter)
719 (*iter)->Close(); 721 (*iter)->Close();
720 } 722 }
721 723
722 bool DockedPanelStrip::is_dragging_panel() const { 724 bool DockedPanelStrip::is_dragging_panel() const {
723 return dragging_panel_index_ != kInvalidPanelIndex; 725 return dragging_panel_index_ != kInvalidPanelIndex;
724 } 726 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698