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

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: review 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 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();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 dragging_panel_index_ = kInvalidPanelIndex; 356 dragging_panel_index_ = kInvalidPanelIndex;
356 357
357 DelayedRemove(); 358 DelayedRemove();
358 } 359 }
359 360
360 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { 361 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) {
361 gfx::Size size = panel->restored_size(); 362 gfx::Size size = panel->restored_size();
362 Panel::ExpansionState expansion_state = panel->expansion_state(); 363 Panel::ExpansionState expansion_state = panel->expansion_state();
363 Panel::ExpansionState old_state = panel->old_expansion_state(); 364 Panel::ExpansionState old_state = panel->old_expansion_state();
364 if (old_state == Panel::IN_OVERFLOW) { 365 if (old_state == Panel::IN_OVERFLOW) {
365 panel_manager_->overflow_strip()->Remove(panel); 366 panel_manager_->overflow_strip()->RemovePanel(panel);
366 AddPanel(panel); 367 AddPanel(panel);
367 panel->SetAppIconVisibility(true); 368 panel->SetAppIconVisibility(true);
368 panel->set_draggable(true); 369 panel->set_draggable(true);
369 } 370 }
370 switch (expansion_state) { 371 switch (expansion_state) {
371 case Panel::EXPANDED: 372 case Panel::EXPANDED:
372 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) 373 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED)
373 DecrementMinimizedPanels(); 374 DecrementMinimizedPanels();
374 break; 375 break;
375 case Panel::TITLE_ONLY: 376 case Panel::TITLE_ONLY:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 DCHECK_LE(minimized_panel_count_, num_panels()); 420 DCHECK_LE(minimized_panel_count_, num_panels());
420 } 421 }
421 422
422 void DockedPanelStrip::DecrementMinimizedPanels() { 423 void DockedPanelStrip::DecrementMinimizedPanels() {
423 minimized_panel_count_--; 424 minimized_panel_count_--;
424 DCHECK_GE(minimized_panel_count_, 0); 425 DCHECK_GE(minimized_panel_count_, 0);
425 if (minimized_panel_count_ == 0) 426 if (minimized_panel_count_ == 0)
426 panel_manager_->mouse_watcher()->RemoveObserver(this); 427 panel_manager_->mouse_watcher()->RemoveObserver(this);
427 } 428 }
428 429
429 void DockedPanelStrip::OnWindowSizeChanged( 430 void DockedPanelStrip::ResizePanelWindow(
430 Panel* panel, const gfx::Size& preferred_window_size) { 431 Panel* panel, const gfx::Size& preferred_window_size) {
431 // The panel width: 432 // The panel width:
432 // * cannot grow or shrink to go beyond [min_width, max_width] 433 // * cannot grow or shrink to go beyond [min_width, max_width]
433 int new_width = preferred_window_size.width(); 434 int new_width = preferred_window_size.width();
434 if (new_width > panel->max_size().width()) 435 if (new_width > panel->max_size().width())
435 new_width = panel->max_size().width(); 436 new_width = panel->max_size().width();
436 if (new_width < panel->min_size().width()) 437 if (new_width < panel->min_size().width())
437 new_width = panel->min_size().width(); 438 new_width = panel->min_size().width();
438 439
439 // The panel height: 440 // The panel height:
(...skipping 23 matching lines...) Expand all
463 if (delta_x != 0 && expansion_state != Panel::IN_OVERFLOW) { 464 if (delta_x != 0 && expansion_state != Panel::IN_OVERFLOW) {
464 bounds.set_width(new_width); 465 bounds.set_width(new_width);
465 bounds.set_x(bounds.x() + delta_x); 466 bounds.set_x(bounds.x() + delta_x);
466 } 467 }
467 468
468 if (bounds != panel->GetBounds()) 469 if (bounds != panel->GetBounds())
469 panel->SetPanelBounds(bounds); 470 panel->SetPanelBounds(bounds);
470 471
471 // Only need to rearrange if panel's width changed. 472 // Only need to rearrange if panel's width changed.
472 if (delta_x != 0) 473 if (delta_x != 0)
473 Rearrange(); 474 RefreshLayout();
474 } 475 }
475 476
476 bool DockedPanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { 477 bool DockedPanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const {
477 // We should always bring up the titlebar if the mouse is over the 478 // We should always bring up the titlebar if the mouse is over the
478 // visible auto-hiding bottom bar. 479 // visible auto-hiding bottom bar.
479 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); 480 AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar();
480 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && 481 if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) &&
481 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == 482 desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) ==
482 AutoHidingDesktopBar::VISIBLE && 483 AutoHidingDesktopBar::VISIBLE &&
483 mouse_y >= display_area_.bottom()) 484 mouse_y >= display_area_.bottom())
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 636
636 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP); 637 DoBringUpOrDownTitlebars(delayed_titlebar_action_ == BRING_UP);
637 delayed_titlebar_action_ = NO_ACTION; 638 delayed_titlebar_action_ = NO_ACTION;
638 } 639 }
639 640
640 void DockedPanelStrip::OnFullScreenModeChanged(bool is_full_screen) { 641 void DockedPanelStrip::OnFullScreenModeChanged(bool is_full_screen) {
641 for (size_t i = 0; i < panels_.size(); ++i) 642 for (size_t i = 0; i < panels_.size(); ++i)
642 panels_[i]->FullScreenModeChanged(is_full_screen); 643 panels_[i]->FullScreenModeChanged(is_full_screen);
643 } 644 }
644 645
645 void DockedPanelStrip::Rearrange() { 646 void DockedPanelStrip::RefreshLayout() {
646 int rightmost_position = StartingRightPosition(); 647 int rightmost_position = StartingRightPosition();
647 648
648 size_t panel_index = 0; 649 size_t panel_index = 0;
649 for (; panel_index < panels_.size(); ++panel_index) { 650 for (; panel_index < panels_.size(); ++panel_index) {
650 Panel* panel = panels_[panel_index]; 651 Panel* panel = panels_[panel_index];
651 gfx::Rect new_bounds(panel->GetBounds()); 652 gfx::Rect new_bounds(panel->GetBounds());
652 int x = rightmost_position - new_bounds.width(); 653 int x = rightmost_position - new_bounds.width();
653 654
654 // TODO(jianli): remove the guard when overflow support is enabled on other 655 // TODO(jianli): remove the guard when overflow support is enabled on other
655 // platforms. http://crbug.com/105073 656 // platforms. http://crbug.com/105073
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 #endif 699 #endif
699 } 700 }
700 701
701 void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) { 702 void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) {
702 if (panels_in_temporary_layout_.erase(panel)) { 703 if (panels_in_temporary_layout_.erase(panel)) {
703 DCHECK(panel->has_temporary_layout()); 704 DCHECK(panel->has_temporary_layout());
704 panel->SetExpansionState(Panel::IN_OVERFLOW); 705 panel->SetExpansionState(Panel::IN_OVERFLOW);
705 } 706 }
706 } 707 }
707 708
708 void DockedPanelStrip::RemoveAll() { 709 void DockedPanelStrip::CloseAll() {
709 // This should only be called at the end of tests to clean up. 710 // This should only be called at the end of tests to clean up.
710 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); 711 DCHECK(dragging_panel_index_ == kInvalidPanelIndex);
711 DCHECK(panels_in_temporary_layout_.empty()); 712 DCHECK(panels_in_temporary_layout_.empty());
712 713
713 // Make a copy of the iterator as closing panels can modify the vector. 714 // Make a copy of the iterator as closing panels can modify the vector.
714 Panels panels_copy = panels_; 715 Panels panels_copy = panels_;
715 716
716 // Start from the bottom to avoid reshuffling. 717 // Start from the bottom to avoid reshuffling.
717 for (Panels::reverse_iterator iter = panels_copy.rbegin(); 718 for (Panels::reverse_iterator iter = panels_copy.rbegin();
718 iter != panels_copy.rend(); ++iter) 719 iter != panels_copy.rend(); ++iter)
719 (*iter)->Close(); 720 (*iter)->Close();
720 } 721 }
721 722
722 bool DockedPanelStrip::is_dragging_panel() const { 723 bool DockedPanelStrip::is_dragging_panel() const {
723 return dragging_panel_index_ != kInvalidPanelIndex; 724 return dragging_panel_index_ != kInvalidPanelIndex;
724 } 725 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/docked_panel_strip.h ('k') | chrome/browser/ui/panels/overflow_panel_strip.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698