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_manager.h" | 5 #include "chrome/browser/ui/panels/panel_manager.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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/browser/ui/window_sizer.h" | 15 #include "chrome/browser/ui/window_sizer.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 // Invalid panel index. | 21 // Invalid panel index. |
22 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); | 22 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
23 | 23 |
24 // Width of spacing between first panel and the right edge of the screen. | 24 // Width of spacing between first panel and the right edge of the screen. |
25 // Leaving a larger gap at the edge of the screen allows access to UI | 25 // Leaving a larger gap at the edge of the screen allows access to UI |
26 // elements located on the bottom right of windows. | 26 // elements located on the bottom right of windows. |
27 const int kRightScreenEdgeSpacingWidth = 24; | 27 const int kRightScreenEdgeSpacingWidth = 24; |
28 | 28 |
29 // Default width and height of a panel. | 29 // Width to height ratio is used to compute the default width or height |
30 const int kPanelDefaultWidth = 240; | 30 // when only one value is provided. |
31 const int kPanelDefaultHeight = 290; | 31 const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio |
32 | 32 |
33 // Maxmium width and height of a panel based on the factor of the working | 33 // Maxmium width and height of a panel based on the factor of the working |
34 // area. | 34 // area. |
35 const double kPanelMaxWidthFactor = 0.35; | 35 const double kPanelMaxWidthFactor = 0.35; |
36 const double kPanelMaxHeightFactor = 0.5; | 36 const double kPanelMaxHeightFactor = 0.5; |
37 | 37 |
38 // Occasionally some system, like Windows, might not bring up or down the bottom | 38 // Occasionally some system, like Windows, might not bring up or down the bottom |
39 // bar when the mouse enters or leaves the bottom screen area. This is the | 39 // bar when the mouse enters or leaves the bottom screen area. This is the |
40 // maximum time we will wait for the bottom bar visibility change notification. | 40 // maximum time we will wait for the bottom bar visibility change notification. |
41 // After the time expires, we bring up/down the titlebars as planned. | 41 // After the time expires, we bring up/down the titlebars as planned. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 AdjustWorkAreaForAutoHidingDesktopBars(); | 98 AdjustWorkAreaForAutoHidingDesktopBars(); |
99 | 99 |
100 Rearrange(panels_.begin(), StartingRightPosition()); | 100 Rearrange(panels_.begin(), StartingRightPosition()); |
101 } | 101 } |
102 | 102 |
103 Panel* PanelManager::CreatePanel(Browser* browser) { | 103 Panel* PanelManager::CreatePanel(Browser* browser) { |
104 // Adjust the width and height to fit into our constraint. | 104 // Adjust the width and height to fit into our constraint. |
105 int width = browser->override_bounds().width(); | 105 int width = browser->override_bounds().width(); |
106 int height = browser->override_bounds().height(); | 106 int height = browser->override_bounds().height(); |
107 | 107 |
108 if (width == 0 && height == 0) { | 108 // Auto resizable is enabled only if no initial size is provided. |
109 width = kPanelDefaultWidth; | 109 bool auto_resize = (width == 0 && height == 0); |
110 height = kPanelDefaultHeight; | 110 |
| 111 if (!auto_resize) { |
| 112 if (height == 0) |
| 113 height = width / kPanelDefaultWidthToHeightRatio; |
| 114 if (width == 0) |
| 115 width = height * kPanelDefaultWidthToHeightRatio; |
111 } | 116 } |
112 | 117 |
113 int max_panel_width = GetMaxPanelWidth(); | 118 int max_panel_width = GetMaxPanelWidth(); |
114 int max_panel_height = GetMaxPanelHeight(); | 119 int max_panel_height = GetMaxPanelHeight(); |
115 | 120 |
116 if (width < kPanelMinWidth) | 121 if (width < kPanelMinWidth) |
117 width = kPanelMinWidth; | 122 width = kPanelMinWidth; |
118 else if (width > max_panel_width) | 123 else if (width > max_panel_width) |
119 width = max_panel_width; | 124 width = max_panel_width; |
120 | 125 |
121 if (height < kPanelMinHeight) | 126 if (height < kPanelMinHeight) |
122 height = kPanelMinHeight; | 127 height = kPanelMinHeight; |
123 else if (height > max_panel_height) | 128 else if (height > max_panel_height) |
124 height = max_panel_height; | 129 height = max_panel_height; |
125 | 130 |
126 int y = adjusted_work_area_.bottom() - height; | 131 int y = adjusted_work_area_.bottom() - height; |
127 int x = GetRightMostAvailablePosition() - width; | 132 int x = GetRightMostAvailablePosition() - width; |
128 | 133 |
129 // Now create the panel with the computed bounds. | 134 // Now create the panel with the computed bounds. |
130 Panel* panel = new Panel(browser, gfx::Rect(x, y, width, height)); | 135 Panel* panel = new Panel(browser, |
131 panel->SetMaxSize(gfx::Size(max_panel_width, max_panel_height)); | 136 gfx::Rect(x, y, width, height), |
| 137 gfx::Size(kPanelMinWidth, kPanelMinHeight), |
| 138 gfx::Size(max_panel_width, max_panel_height), |
| 139 auto_resize); |
132 panels_.push_back(panel); | 140 panels_.push_back(panel); |
133 | 141 |
134 content::NotificationService::current()->Notify( | 142 content::NotificationService::current()->Notify( |
135 chrome::NOTIFICATION_PANEL_ADDED, | 143 chrome::NOTIFICATION_PANEL_ADDED, |
136 content::Source<Panel>(panel), | 144 content::Source<Panel>(panel), |
137 content::NotificationService::NoDetails()); | 145 content::NotificationService::NoDetails()); |
138 | 146 |
139 return panel; | 147 return panel; |
140 } | 148 } |
141 | 149 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 | 628 |
621 // Start from the bottom to avoid reshuffling. | 629 // Start from the bottom to avoid reshuffling. |
622 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 630 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
623 iter != panels_copy.rend(); ++iter) | 631 iter != panels_copy.rend(); ++iter) |
624 (*iter)->Close(); | 632 (*iter)->Close(); |
625 } | 633 } |
626 | 634 |
627 bool PanelManager::is_dragging_panel() const { | 635 bool PanelManager::is_dragging_panel() const { |
628 return dragging_panel_index_ != kInvalidPanelIndex; | 636 return dragging_panel_index_ != kInvalidPanelIndex; |
629 } | 637 } |
OLD | NEW |