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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 const int kDelayBeforeCollapsingFromTitleOnlyStateMs = 2000; | 44 const int kDelayBeforeCollapsingFromTitleOnlyStateMs = 2000; |
45 #else | 45 #else |
46 const int kDelayBeforeCollapsingFromTitleOnlyStateMs = 0; | 46 const int kDelayBeforeCollapsingFromTitleOnlyStateMs = 0; |
47 #endif | 47 #endif |
48 | 48 |
49 // After focus changed, one panel lost active status, another got it, | 49 // After focus changed, one panel lost active status, another got it, |
50 // we refresh layout with a delay. | 50 // we refresh layout with a delay. |
51 const int kRefreshLayoutAfterActivePanelChangeDelayMs = 200; // arbitrary | 51 const int kRefreshLayoutAfterActivePanelChangeDelayMs = 200; // arbitrary |
52 | 52 |
53 // The minimum panel width when it is "squeezed" in the docked strip | 53 // The minimum panel width when it is "squeezed" in the docked strip |
54 // due to lack of space. | 54 // due to lack of space. Arbitrary, should still allow the titlebar's buttons |
55 const int kMinPanelWidthForDisplay = 26; | 55 // to be somewhat useful. At least Close button should be functional. |
56 const int kMinPanelWidthForDisplay = 70; | |
jennb
2012/04/28 00:09:49
Why don't we just make this the same as kPanelMinW
Dmitry Titov
2012/04/28 00:57:40
Done.
| |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 // static | 59 // static |
59 const int DockedPanelStrip::kPanelMinWidth = 100; | 60 const int DockedPanelStrip::kPanelMinWidth = 100; |
60 const int DockedPanelStrip::kPanelMinHeight = 20; | 61 const int DockedPanelStrip::kPanelMinHeight = 20; |
61 | 62 |
62 DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager) | 63 DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager) |
63 : PanelStrip(PanelStrip::DOCKED), | 64 : PanelStrip(PanelStrip::DOCKED), |
64 panel_manager_(panel_manager), | 65 panel_manager_(panel_manager), |
65 minimized_panel_count_(0), | 66 minimized_panel_count_(0), |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 height = kPanelMinHeight; | 155 height = kPanelMinHeight; |
155 else if (height > max_panel_height) | 156 else if (height > max_panel_height) |
156 height = max_panel_height; | 157 height = max_panel_height; |
157 | 158 |
158 full_size = gfx::Size(width, height); | 159 full_size = gfx::Size(width, height); |
159 panel->set_full_size(full_size); | 160 panel->set_full_size(full_size); |
160 gfx::Point pt = GetDefaultPositionForPanel(full_size); | 161 gfx::Point pt = GetDefaultPositionForPanel(full_size); |
161 | 162 |
162 panel->Initialize(gfx::Rect(pt.x(), pt.y(), width, height)); | 163 panel->Initialize(gfx::Rect(pt.x(), pt.y(), width, height)); |
163 | 164 |
165 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | |
166 gfx::Size(max_panel_width, max_panel_height)); | |
167 | |
164 InsertExistingPanelAtDefaultPosition(panel, true /*update_bounds*/); | 168 InsertExistingPanelAtDefaultPosition(panel, true /*update_bounds*/); |
165 } | 169 } |
166 | 170 |
167 void DockedPanelStrip::InsertExistingPanelAtKnownPosition(Panel* panel) { | 171 void DockedPanelStrip::InsertExistingPanelAtKnownPosition(Panel* panel) { |
168 DCHECK(panel->initialized()); | 172 DCHECK(panel->initialized()); |
169 | 173 |
170 int x = panel->GetBounds().x(); | 174 int x = panel->GetBounds().x(); |
171 Panels::iterator iter = panels_.begin(); | 175 Panels::iterator iter = panels_.begin(); |
172 for (; iter != panels_.end(); ++iter) | 176 for (; iter != panels_.end(); ++iter) |
173 if (x > (*iter)->GetBounds().x()) | 177 if (x > (*iter)->GetBounds().x()) |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 DCHECK_LE(minimized_panel_count_, num_panels()); | 569 DCHECK_LE(minimized_panel_count_, num_panels()); |
566 } | 570 } |
567 | 571 |
568 void DockedPanelStrip::ResizePanelWindow( | 572 void DockedPanelStrip::ResizePanelWindow( |
569 Panel* panel, | 573 Panel* panel, |
570 const gfx::Size& preferred_window_size) { | 574 const gfx::Size& preferred_window_size) { |
571 DCHECK_EQ(this, panel->panel_strip()); | 575 DCHECK_EQ(this, panel->panel_strip()); |
572 // Make sure the new size does not violate panel's size restrictions. | 576 // Make sure the new size does not violate panel's size restrictions. |
573 gfx::Size new_size(preferred_window_size.width(), | 577 gfx::Size new_size(preferred_window_size.width(), |
574 preferred_window_size.height()); | 578 preferred_window_size.height()); |
575 panel->ClampSize(&new_size); | 579 new_size = panel->ClampSize(new_size); |
576 | 580 |
577 if (new_size == panel->full_size()) | 581 if (new_size == panel->full_size()) |
578 return; | 582 return; |
579 | 583 |
580 panel->set_full_size(new_size); | 584 panel->set_full_size(new_size); |
581 | 585 |
582 RefreshLayout(); | 586 RefreshLayout(); |
583 } | 587 } |
584 | 588 |
585 bool DockedPanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 589 bool DockedPanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 // Make a copy of the iterator as closing panels can modify the vector. | 865 // Make a copy of the iterator as closing panels can modify the vector. |
862 Panels panels_copy = panels_; | 866 Panels panels_copy = panels_; |
863 | 867 |
864 // Start from the bottom to avoid reshuffling. | 868 // Start from the bottom to avoid reshuffling. |
865 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 869 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
866 iter != panels_copy.rend(); ++iter) | 870 iter != panels_copy.rend(); ++iter) |
867 (*iter)->Close(); | 871 (*iter)->Close(); |
868 } | 872 } |
869 | 873 |
870 void DockedPanelStrip::UpdatePanelOnStripChange(Panel* panel) { | 874 void DockedPanelStrip::UpdatePanelOnStripChange(Panel* panel) { |
871 // Always update limits, even on existing panels, in case the limits changed | |
jennb
2012/04/28 00:09:49
Still want to update the limits here if panel is a
Dmitry Titov
2012/04/28 00:57:40
Done. This leaves the panels that are not auto-res
| |
872 // while panel was out of the strip. | |
873 int max_panel_width = GetMaxPanelWidth(); | |
874 int max_panel_height = GetMaxPanelHeight(); | |
875 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | |
876 gfx::Size(max_panel_width, max_panel_height)); | |
877 | |
878 panel->set_attention_mode(Panel::USE_PANEL_ATTENTION); | 875 panel->set_attention_mode(Panel::USE_PANEL_ATTENTION); |
879 panel->SetAppIconVisibility(true); | 876 panel->SetAppIconVisibility(true); |
880 panel->SetAlwaysOnTop(true); | 877 panel->SetAlwaysOnTop(true); |
881 panel->EnableResizeByMouse(true); | 878 panel->EnableResizeByMouse(true); |
882 } | 879 } |
883 | 880 |
884 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { | 881 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { |
885 // Refresh layout, but wait till active states settle. | 882 // Refresh layout, but wait till active states settle. |
886 // This lets us avoid refreshing too many times when one panel loses | 883 // This lets us avoid refreshing too many times when one panel loses |
887 // focus and another gains it. | 884 // focus and another gains it. |
888 refresh_action_factory_.InvalidateWeakPtrs(); | 885 refresh_action_factory_.InvalidateWeakPtrs(); |
889 MessageLoop::current()->PostDelayedTask( | 886 MessageLoop::current()->PostDelayedTask( |
890 FROM_HERE, | 887 FROM_HERE, |
891 base::Bind(&DockedPanelStrip::RefreshLayout, | 888 base::Bind(&DockedPanelStrip::RefreshLayout, |
892 refresh_action_factory_.GetWeakPtr()), | 889 refresh_action_factory_.GetWeakPtr()), |
893 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( | 890 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( |
894 kRefreshLayoutAfterActivePanelChangeDelayMs))); | 891 kRefreshLayoutAfterActivePanelChangeDelayMs))); |
895 } | 892 } |
896 | 893 |
897 bool DockedPanelStrip::HasPanel(Panel* panel) const { | 894 bool DockedPanelStrip::HasPanel(Panel* panel) const { |
898 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 895 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
899 } | 896 } |
OLD | NEW |