Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #if defined(TOOLKIT_GTK) | 43 #if defined(TOOLKIT_GTK) |
| 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 | |
| 54 // due to lack of space. | |
| 55 const int kMinPanelWidthForDisplay = 26; | |
| 56 } // namespace | 53 } // namespace |
| 57 | 54 |
| 58 // static | 55 // static |
| 59 const int DockedPanelStrip::kPanelMinWidth = 100; | 56 // These numbers are semi-arbitrary. |
| 57 // Motivation for 'width' is to make main buttons on the titlebar functional. | |
| 58 // Motivation for height is to allow autosized tightly-wrapped panel with a | |
|
jennb
2012/04/30 17:03:31
The height comment is wrong as a height of 20 is l
| |
| 59 // single line of text. | |
| 60 const int DockedPanelStrip::kPanelMinWidth = 80; | |
| 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), |
| 66 are_titlebars_up_(false), | 67 are_titlebars_up_(false), |
| 67 minimizing_all_(false), | 68 minimizing_all_(false), |
| 68 delayed_titlebar_action_(NO_ACTION), | 69 delayed_titlebar_action_(NO_ACTION), |
| 69 titlebar_action_factory_(this), | 70 titlebar_action_factory_(this), |
| (...skipping 84 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 | 848 |
| 845 ++num_processed; | 849 ++num_processed; |
| 846 } | 850 } |
| 847 } | 851 } |
| 848 | 852 |
| 849 int DockedPanelStrip::WidthToDisplayPanelInStrip(bool is_for_active_panel, | 853 int DockedPanelStrip::WidthToDisplayPanelInStrip(bool is_for_active_panel, |
| 850 double squeeze_factor, | 854 double squeeze_factor, |
| 851 int full_width) const { | 855 int full_width) const { |
| 852 if (is_for_active_panel) | 856 if (is_for_active_panel) |
| 853 return full_width; | 857 return full_width; |
| 854 return std::max(kMinPanelWidthForDisplay, | 858 return std::max(kPanelMinWidth, |
| 855 static_cast<int>(floor(full_width * squeeze_factor))); | 859 static_cast<int>(floor(full_width * squeeze_factor))); |
| 856 } | 860 } |
| 857 | 861 |
| 858 void DockedPanelStrip::CloseAll() { | 862 void DockedPanelStrip::CloseAll() { |
| 859 // This should only be called at the end of tests to clean up. | 863 // This should only be called at the end of tests to clean up. |
| 860 | 864 |
| 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 | 875 // Update limits if the panel is still autosizable, in case the limit has |
| 872 // while panel was out of the strip. | 876 // changed. If the panel is not autoresizable, then it's either was resized |
|
jennb
2012/04/30 17:03:31
nit: it's either was -> it was
| |
| 873 int max_panel_width = GetMaxPanelWidth(); | 877 // by the user or by the app via API. |
| 874 int max_panel_height = GetMaxPanelHeight(); | 878 if (panel->auto_resizable()) { |
| 875 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | 879 int max_panel_width = GetMaxPanelWidth(); |
| 876 gfx::Size(max_panel_width, max_panel_height)); | 880 int max_panel_height = GetMaxPanelHeight(); |
| 877 | 881 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
| 882 gfx::Size(max_panel_width, max_panel_height)); | |
| 883 } | |
| 878 panel->set_attention_mode(Panel::USE_PANEL_ATTENTION); | 884 panel->set_attention_mode(Panel::USE_PANEL_ATTENTION); |
| 879 panel->SetAppIconVisibility(true); | 885 panel->SetAppIconVisibility(true); |
| 880 panel->SetAlwaysOnTop(true); | 886 panel->SetAlwaysOnTop(true); |
| 881 panel->EnableResizeByMouse(true); | 887 panel->EnableResizeByMouse(true); |
| 882 } | 888 } |
| 883 | 889 |
| 884 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { | 890 void DockedPanelStrip::OnPanelActiveStateChanged(Panel* panel) { |
| 885 // Refresh layout, but wait till active states settle. | 891 // Refresh layout, but wait till active states settle. |
| 886 // This lets us avoid refreshing too many times when one panel loses | 892 // This lets us avoid refreshing too many times when one panel loses |
| 887 // focus and another gains it. | 893 // focus and another gains it. |
| 888 refresh_action_factory_.InvalidateWeakPtrs(); | 894 refresh_action_factory_.InvalidateWeakPtrs(); |
| 889 MessageLoop::current()->PostDelayedTask( | 895 MessageLoop::current()->PostDelayedTask( |
| 890 FROM_HERE, | 896 FROM_HERE, |
| 891 base::Bind(&DockedPanelStrip::RefreshLayout, | 897 base::Bind(&DockedPanelStrip::RefreshLayout, |
| 892 refresh_action_factory_.GetWeakPtr()), | 898 refresh_action_factory_.GetWeakPtr()), |
| 893 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( | 899 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( |
| 894 kRefreshLayoutAfterActivePanelChangeDelayMs))); | 900 kRefreshLayoutAfterActivePanelChangeDelayMs))); |
| 895 } | 901 } |
| 896 | 902 |
| 897 bool DockedPanelStrip::HasPanel(Panel* panel) const { | 903 bool DockedPanelStrip::HasPanel(Panel* panel) const { |
| 898 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 904 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
| 899 } | 905 } |
| OLD | NEW |