OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/panel_strip.h" | 5 #include "chrome/browser/ui/panels/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" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/panels/panel_manager.h" | 13 #include "chrome/browser/ui/panels/panel_manager.h" |
14 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 14 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
15 #include "chrome/browser/ui/panels/panel_overflow_strip.h" | |
15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 // Invalid panel index. | 21 // Invalid panel index. |
21 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); | 22 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
22 | 23 |
23 // Width to height ratio is used to compute the default width or height | 24 // Width to height ratio is used to compute the default width or height |
24 // when only one value is provided. | 25 // when only one value is provided. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 DCHECK_EQ(0, minimized_panel_count_); | 67 DCHECK_EQ(0, minimized_panel_count_); |
67 } | 68 } |
68 | 69 |
69 void PanelStrip::SetDisplayArea(const gfx::Rect& new_area) { | 70 void PanelStrip::SetDisplayArea(const gfx::Rect& new_area) { |
70 if (display_area_ == new_area) | 71 if (display_area_ == new_area) |
71 return; | 72 return; |
72 | 73 |
73 gfx::Rect old_area = display_area_; | 74 gfx::Rect old_area = display_area_; |
74 display_area_ = new_area; | 75 display_area_ = new_area; |
75 | 76 |
76 if (panels_.empty() || new_area.width() == old_area.width()) | 77 if (panels_.empty()) |
77 return; | 78 return; |
78 | 79 |
79 if (new_area.width() < old_area.width()) | 80 Rearrange(); |
80 Rearrange(); | |
81 else | |
82 MovePanelsFromOverflowIfNeeded(); | |
83 } | 81 } |
84 | 82 |
85 void PanelStrip::AddPanel(Panel* panel) { | 83 void PanelStrip::AddPanel(Panel* panel) { |
86 // Always update limits, even for exiting panels, in case the maximums changed | 84 // Always update limits, even for exiting panels, in case the maximums changed |
87 // while panel was out of the strip. | 85 // while panel was out of the strip. |
88 int max_panel_width = GetMaxPanelWidth(); | 86 int max_panel_width = GetMaxPanelWidth(); |
89 int max_panel_height = GetMaxPanelHeight(); | 87 int max_panel_height = GetMaxPanelHeight(); |
90 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | 88 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
91 gfx::Size(max_panel_width, max_panel_height)); | 89 gfx::Size(max_panel_width, max_panel_height)); |
92 | 90 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 height = kPanelMinHeight; | 123 height = kPanelMinHeight; |
126 else if (height > max_panel_height) | 124 else if (height > max_panel_height) |
127 height = max_panel_height; | 125 height = max_panel_height; |
128 | 126 |
129 panel->set_restored_size(gfx::Size(width, height)); | 127 panel->set_restored_size(gfx::Size(width, height)); |
130 int x = GetRightMostAvailablePosition() - width; | 128 int x = GetRightMostAvailablePosition() - width; |
131 int y = display_area_.bottom() - height; | 129 int y = display_area_.bottom() - height; |
132 | 130 |
133 // Keep panel visible in the strip even if overlap would occur. | 131 // Keep panel visible in the strip even if overlap would occur. |
134 // Panel is moved to overflow from the strip after a delay. | 132 // Panel is moved to overflow from the strip after a delay. |
133 // TODO(jianli): remove the guard when overflow support is enabled on other | |
134 // platforms. http://crbug.com/105073 | |
135 #if defined(OS_WIN) | |
135 if (x < display_area_.x()) { | 136 if (x < display_area_.x()) { |
136 x = display_area_.x(); | 137 x = display_area_.x(); |
137 int delay_ms = remove_delays_for_testing_ ? 0 : | 138 int delay_ms = remove_delays_for_testing_ ? 0 : |
138 kMoveNewPanelToOverflowDelayMilliseconds; | 139 kMoveNewPanelToOverflowDelayMilliseconds; |
139 MessageLoop::current()->PostDelayedTask( | 140 MessageLoop::current()->PostDelayedTask( |
140 FROM_HERE, | 141 FROM_HERE, |
141 base::Bind(&PanelStrip::MovePanelToOverflow, | 142 base::Bind(&PanelStrip::MovePanelToOverflow, |
142 base::Unretained(this), | 143 base::Unretained(this), |
143 panel, | 144 panel, |
144 true), // new panel | 145 true), // new panel |
145 delay_ms); | 146 delay_ms); |
146 } | 147 } |
148 #endif | |
147 panel->Initialize(gfx::Rect(x, y, width, height)); | 149 panel->Initialize(gfx::Rect(x, y, width, height)); |
148 } | 150 } |
149 | 151 |
150 panels_.push_back(panel); | 152 panels_.push_back(panel); |
151 } | 153 } |
152 | 154 |
153 int PanelStrip::GetMaxPanelWidth() const { | 155 int PanelStrip::GetMaxPanelWidth() const { |
154 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); | 156 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); |
155 } | 157 } |
156 | 158 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 panels_[dragging_panel_index_]->SetPanelBounds( | 329 panels_[dragging_panel_index_]->SetPanelBounds( |
328 dragging_panel_bounds_); | 330 dragging_panel_bounds_); |
329 } | 331 } |
330 | 332 |
331 dragging_panel_index_ = kInvalidPanelIndex; | 333 dragging_panel_index_ = kInvalidPanelIndex; |
332 | 334 |
333 DelayedRemove(); | 335 DelayedRemove(); |
334 } | 336 } |
335 | 337 |
336 void PanelStrip::OnPanelExpansionStateChanged( | 338 void PanelStrip::OnPanelExpansionStateChanged( |
337 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { | 339 Panel* panel, Panel::ExpansionState old_state) { |
338 DCHECK_NE(new_state, old_state); | 340 gfx::Size size = panel->restored_size(); |
339 switch (new_state) { | 341 Panel::ExpansionState expansion_state = panel->expansion_state(); |
342 switch (expansion_state) { | |
340 case Panel::EXPANDED: | 343 case Panel::EXPANDED: |
341 DecrementMinimizedPanels(); | 344 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) |
345 DecrementMinimizedPanels(); | |
346 break; | |
347 case Panel::TITLE_ONLY: | |
348 size.set_height(panel->TitleOnlyHeight()); | |
349 if (old_state == Panel::EXPANDED) | |
350 IncrementMinimizedPanels(); | |
342 break; | 351 break; |
343 case Panel::MINIMIZED: | 352 case Panel::MINIMIZED: |
344 case Panel::TITLE_ONLY: | 353 size.set_height(Panel::kMinimizedPanelHeight); |
345 if (old_state == Panel::EXPANDED) | 354 if (old_state == Panel::EXPANDED) |
346 IncrementMinimizedPanels(); | 355 IncrementMinimizedPanels(); |
347 break; | 356 break; |
348 default: | 357 default: |
358 NOTREACHED(); | |
349 break; | 359 break; |
350 } | 360 } |
361 | |
362 int bottom = GetBottomPositionForExpansionState(expansion_state); | |
363 gfx::Rect bounds = panel->GetBounds(); | |
364 panel->SetPanelBounds( | |
365 gfx::Rect(bounds.right() - size.width(), | |
366 bottom - size.height(), | |
367 size.width(), | |
368 size.height())); | |
351 } | 369 } |
352 | 370 |
353 void PanelStrip::IncrementMinimizedPanels() { | 371 void PanelStrip::IncrementMinimizedPanels() { |
354 minimized_panel_count_++; | 372 minimized_panel_count_++; |
355 if (minimized_panel_count_ == 1) | 373 if (minimized_panel_count_ == 1) |
356 panel_manager_->mouse_watcher()->AddObserver(this); | 374 panel_manager_->mouse_watcher()->AddObserver(this); |
357 DCHECK_LE(minimized_panel_count_, num_panels()); | 375 DCHECK_LE(minimized_panel_count_, num_panels()); |
358 } | 376 } |
359 | 377 |
360 void PanelStrip::DecrementMinimizedPanels() { | 378 void PanelStrip::DecrementMinimizedPanels() { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 | 584 |
567 void PanelStrip::Rearrange() { | 585 void PanelStrip::Rearrange() { |
568 int rightmost_position = StartingRightPosition(); | 586 int rightmost_position = StartingRightPosition(); |
569 | 587 |
570 size_t panel_index = 0; | 588 size_t panel_index = 0; |
571 for (; panel_index < panels_.size(); ++panel_index) { | 589 for (; panel_index < panels_.size(); ++panel_index) { |
572 Panel* panel = panels_[panel_index]; | 590 Panel* panel = panels_[panel_index]; |
573 gfx::Rect new_bounds(panel->GetBounds()); | 591 gfx::Rect new_bounds(panel->GetBounds()); |
574 int x = rightmost_position - new_bounds.width(); | 592 int x = rightmost_position - new_bounds.width(); |
575 | 593 |
594 // TODO(jianli): remove the guard when overflow support is enabled on other | |
595 // platforms. http://crbug.com/105073 | |
596 #if defined(OS_WIN) | |
576 if (x < display_area_.x()) { | 597 if (x < display_area_.x()) { |
577 MovePanelsToOverflow(panel_index); | 598 MovePanelsToOverflow(panel_index); |
578 break; | 599 break; |
579 } | 600 } |
601 #endif | |
580 | 602 |
581 new_bounds.set_x(rightmost_position - new_bounds.width()); | 603 new_bounds.set_x(x); |
jennb
2011/12/03 00:06:54
Leave this line the way it was, but move the guard
| |
582 new_bounds.set_y( | 604 new_bounds.set_y( |
583 GetBottomPositionForExpansionState(panel->expansion_state()) - | 605 GetBottomPositionForExpansionState(panel->expansion_state()) - |
584 new_bounds.height()); | 606 new_bounds.height()); |
585 panel->SetPanelBounds(new_bounds); | 607 panel->SetPanelBounds(new_bounds); |
586 | 608 |
587 rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; | 609 rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; |
588 } | 610 } |
589 | 611 |
612 // TODO(jianli): remove the guard when overflow support is enabled on other | |
613 // platforms. http://crbug.com/105073 | |
614 #if defined(OS_WIN) | |
590 if (panel_index == panels_.size()) | 615 if (panel_index == panels_.size()) |
591 MovePanelsFromOverflowIfNeeded(); | 616 MovePanelsFromOverflowIfNeeded(); |
617 #endif | |
592 } | 618 } |
593 | 619 |
594 void PanelStrip::MovePanelsToOverflow(size_t overflow_point) { | 620 void PanelStrip::MovePanelsToOverflow(size_t overflow_point) { |
595 DCHECK(overflow_point >= 0); | 621 DCHECK(overflow_point >= 0); |
596 // Move panels in reverse to maintain their order. | 622 // Move panels in reverse to maintain their order. |
597 for (size_t i = panels_.size() - 1; i >= overflow_point; --i) | 623 for (size_t i = panels_.size() - 1; i >= overflow_point; --i) |
598 MovePanelToOverflow(panels_[i], false); | 624 MovePanelToOverflow(panels_[i], false); |
599 } | 625 } |
600 | 626 |
601 void PanelStrip::MovePanelToOverflow(Panel* panel, bool is_new) { | 627 void PanelStrip::MovePanelToOverflow(Panel* panel, bool is_new) { |
602 if (!DoRemove(panel)) | 628 if (!DoRemove(panel)) |
603 return; | 629 return; |
604 | 630 |
605 // TODO(jianli): Replace with the real code using overflow strip. | 631 panel_manager_->panel_overflow_strip()->AddPanel(panel, is_new); |
606 // panel_manager_->panel_overflow_strip()->AddPanel(panel, is_new); | |
607 } | 632 } |
608 | 633 |
609 void PanelStrip::MovePanelsFromOverflowIfNeeded() { | 634 void PanelStrip::MovePanelsFromOverflowIfNeeded() { |
610 // TODO(jianli): Replace with the real code using overflow strip. | 635 PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip(); |
611 // PanelOverflowStrip* overflow = panel_manager_->panel_overflow_strip(); | 636 Panel* overflow_panel; |
612 // Panel* candidate; | 637 while ((overflow_panel = overflow_strip->first_panel()) && |
613 // while (candidate = overflow->FirstPanel() && | 638 GetRightMostAvailablePosition() - |
614 // GetRightMostAvailablePosition - | 639 overflow_panel->restored_size().width() >= display_area_.x()) { |
615 // candidate->GetRestoredSize().width() >= display_area_.x()) { | 640 overflow_strip->Remove(overflow_panel); |
616 // overflow->Remove(candidate); | 641 AddPanel(overflow_panel); |
617 // AddPanel(candidate); | 642 } |
618 // } | |
619 } | 643 } |
620 | 644 |
621 void PanelStrip::RemoveAll() { | 645 void PanelStrip::RemoveAll() { |
622 // This should not be called when we're in the process of dragging. | 646 // This should not be called when we're in the process of dragging. |
623 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); | 647 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); |
624 | 648 |
625 // Make a copy of the iterator as closing panels can modify the vector. | 649 // Make a copy of the iterator as closing panels can modify the vector. |
626 Panels panels_copy = panels_; | 650 Panels panels_copy = panels_; |
627 | 651 |
628 // Start from the bottom to avoid reshuffling. | 652 // Start from the bottom to avoid reshuffling. |
629 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 653 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
630 iter != panels_copy.rend(); ++iter) | 654 iter != panels_copy.rend(); ++iter) |
631 (*iter)->Close(); | 655 (*iter)->Close(); |
632 } | 656 } |
633 | 657 |
634 bool PanelStrip::is_dragging_panel() const { | 658 bool PanelStrip::is_dragging_panel() const { |
635 return dragging_panel_index_ != kInvalidPanelIndex; | 659 return dragging_panel_index_ != kInvalidPanelIndex; |
636 } | 660 } |
OLD | NEW |