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.h" | 5 #include "chrome/browser/ui/panels/panel.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/extensions/extension_prefs.h" | 8 #include "chrome/browser/extensions/extension_prefs.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/tabs/tab_strip_model.h" | 11 #include "chrome/browser/tabs/tab_strip_model.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/panels/native_panel.h" | 13 #include "chrome/browser/ui/panels/native_panel.h" |
14 #include "chrome/browser/ui/panels/panel_manager.h" | 14 #include "chrome/browser/ui/panels/panel_manager.h" |
15 #include "chrome/browser/ui/panels/panel_overflow_strip.h" | |
16 #include "chrome/browser/ui/panels/panel_strip.h" | |
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
18 #include "chrome/browser/ui/window_sizer.h" | 16 #include "chrome/browser/ui/window_sizer.h" |
19 #include "chrome/browser/web_applications/web_app.h" | 17 #include "chrome/browser/web_applications/web_app.h" |
20 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
21 #include "content/browser/renderer_host/render_view_host.h" | 19 #include "content/browser/renderer_host/render_view_host.h" |
22 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
23 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
25 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
26 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
27 | 25 |
28 // static | 26 // static |
29 const Extension* Panel::GetExtensionFromBrowser(Browser* browser) { | 27 const Extension* Panel::GetExtensionFromBrowser(Browser* browser) { |
30 // Find the extension. When we create a panel from an extension, the extension | 28 // Find the extension. When we create a panel from an extension, the extension |
31 // ID is passed as the app name to the Browser. | 29 // ID is passed as the app name to the Browser. |
32 ExtensionService* extension_service = | 30 ExtensionService* extension_service = |
33 browser->GetProfile()->GetExtensionService(); | 31 browser->GetProfile()->GetExtensionService(); |
34 return extension_service->GetExtensionById( | 32 return extension_service->GetExtensionById( |
35 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); | 33 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); |
36 } | 34 } |
37 | 35 |
38 Panel::Panel(Browser* browser, const gfx::Size& requested_size) | 36 Panel::Panel(Browser* browser, const gfx::Size& requested_size) |
39 : browser_(browser), | 37 : browser_(browser), |
40 initialized_(false), | 38 initialized_(false), |
| 39 has_temporary_layout_(false), |
41 restored_size_(requested_size), | 40 restored_size_(requested_size), |
42 auto_resizable_(false), | 41 auto_resizable_(false), |
43 expansion_state_(EXPANDED) { | 42 expansion_state_(EXPANDED), |
| 43 app_icon_visible_(true) { |
44 } | 44 } |
45 | 45 |
46 Panel::~Panel() { | 46 Panel::~Panel() { |
47 // Invoked by native panel destructor. Do not access native_panel_ here. | 47 // Invoked by native panel destructor. Do not access native_panel_ here. |
48 } | 48 } |
49 | 49 |
50 void Panel::Initialize(const gfx::Rect& bounds) { | 50 void Panel::Initialize(const gfx::Rect& bounds) { |
51 DCHECK(!initialized_); | 51 DCHECK(!initialized_); |
52 DCHECK(!bounds.IsEmpty()); | 52 DCHECK(!bounds.IsEmpty()); |
53 initialized_ = true; | 53 initialized_ = true; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return; | 113 return; |
114 | 114 |
115 DCHECK(min_size.width() <= max_size.width()); | 115 DCHECK(min_size.width() <= max_size.width()); |
116 DCHECK(min_size.height() <= max_size.height()); | 116 DCHECK(min_size.height() <= max_size.height()); |
117 min_size_ = min_size; | 117 min_size_ = min_size; |
118 max_size_ = max_size; | 118 max_size_ = max_size; |
119 | 119 |
120 ConfigureAutoResize(browser()->GetSelectedTabContents()); | 120 ConfigureAutoResize(browser()->GetSelectedTabContents()); |
121 } | 121 } |
122 | 122 |
| 123 void Panel::SetAppIconVisibility(bool visible) { |
| 124 if (app_icon_visible_ == visible) |
| 125 return; |
| 126 app_icon_visible_ = visible; |
| 127 native_panel_->SetPanelAppIconVisibility(visible); |
| 128 } |
| 129 |
123 void Panel::SetExpansionState(ExpansionState new_state) { | 130 void Panel::SetExpansionState(ExpansionState new_state) { |
124 if (expansion_state_ == new_state) | 131 if (expansion_state_ == new_state) |
125 return; | 132 return; |
126 ExpansionState old_state = expansion_state_; | 133 ExpansionState old_state = expansion_state_; |
127 expansion_state_ = new_state; | 134 expansion_state_ = new_state; |
128 | 135 |
129 manager()->OnPanelExpansionStateChanged(this, old_state); | 136 manager()->OnPanelExpansionStateChanged(this, old_state); |
130 | 137 |
131 // The minimized panel should not get the focus. | 138 // The minimized panel should not get the focus. |
132 if (expansion_state_ == MINIMIZED) | 139 if (expansion_state_ == MINIMIZED) |
133 Deactivate(); | 140 Deactivate(); |
134 | 141 |
135 content::NotificationService::current()->Notify( | 142 content::NotificationService::current()->Notify( |
136 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | 143 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, |
137 content::Source<Panel>(this), | 144 content::Source<Panel>(this), |
138 content::NotificationService::NoDetails()); | 145 content::NotificationService::NoDetails()); |
139 } | 146 } |
140 | 147 |
141 bool Panel::ShouldBringUpTitlebar(int mouse_x, int mouse_y) const { | |
142 // Skip the expanded panel. | |
143 if (expansion_state_ == EXPANDED) | |
144 return false; | |
145 | |
146 // If the panel is showing titlebar only, we want to keep it up when it is | |
147 // being dragged. | |
148 if (expansion_state_ == TITLE_ONLY && manager()->is_dragging_panel()) | |
149 return true; | |
150 | |
151 // We do not want to bring up other minimized panels if the mouse is over the | |
152 // panel that pops up the title-bar to attract attention. | |
153 if (native_panel_->IsDrawingAttention()) | |
154 return false; | |
155 | |
156 gfx::Rect bounds = native_panel_->GetPanelBounds(); | |
157 return bounds.x() <= mouse_x && mouse_x <= bounds.right() && | |
158 mouse_y >= bounds.y(); | |
159 } | |
160 | |
161 bool Panel::IsDrawingAttention() const { | 148 bool Panel::IsDrawingAttention() const { |
162 return native_panel_->IsDrawingAttention(); | 149 return native_panel_->IsDrawingAttention(); |
163 } | 150 } |
164 | 151 |
165 void Panel::FullScreenModeChanged(bool is_full_screen) { | 152 void Panel::FullScreenModeChanged(bool is_full_screen) { |
166 native_panel_->FullScreenModeChanged(is_full_screen); | 153 native_panel_->FullScreenModeChanged(is_full_screen); |
167 } | 154 } |
168 | 155 |
169 void Panel::Show() { | 156 void Panel::Show() { |
170 // Don't show panel as active if it is in overflow state. | 157 // Don't show panel as active if it is in overflow state. |
(...skipping 11 matching lines...) Expand all Loading... |
182 // Ignore any SetBounds requests since the bounds are completely controlled | 169 // Ignore any SetBounds requests since the bounds are completely controlled |
183 // by panel manager. | 170 // by panel manager. |
184 } | 171 } |
185 | 172 |
186 // Close() may be called multiple times if the browser window is not ready to | 173 // Close() may be called multiple times if the browser window is not ready to |
187 // close on the first attempt. | 174 // close on the first attempt. |
188 void Panel::Close() { | 175 void Panel::Close() { |
189 native_panel_->ClosePanel(); | 176 native_panel_->ClosePanel(); |
190 } | 177 } |
191 | 178 |
192 void Panel::MoveOutOfOverflow() { | |
193 if (expansion_state_ != Panel::IN_OVERFLOW) | |
194 return; | |
195 manager()->panel_overflow_strip()->Remove(this); | |
196 manager()->panel_strip()->AddPanel(this); | |
197 } | |
198 | |
199 void Panel::Activate() { | 179 void Panel::Activate() { |
200 MoveOutOfOverflow(); | |
201 | |
202 // Make sure the panel is expanded when activated programmatically, | 180 // Make sure the panel is expanded when activated programmatically, |
203 // so the user input does not go into collapsed window. | 181 // so the user input does not go into collapsed window. |
204 SetExpansionState(Panel::EXPANDED); | 182 SetExpansionState(Panel::EXPANDED); |
205 native_panel_->ActivatePanel(); | 183 native_panel_->ActivatePanel(); |
206 } | 184 } |
207 | 185 |
208 void Panel::Deactivate() { | 186 void Panel::Deactivate() { |
209 native_panel_->DeactivatePanel(); | 187 native_panel_->DeactivatePanel(); |
210 } | 188 } |
211 | 189 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 native_panel_->ContentSizeFromWindowSize(max_size_)); | 610 native_panel_->ContentSizeFromWindowSize(max_size_)); |
633 } | 611 } |
634 | 612 |
635 void Panel::OnWindowSizeAvailable() { | 613 void Panel::OnWindowSizeAvailable() { |
636 ConfigureAutoResize(browser()->GetSelectedTabContents()); | 614 ConfigureAutoResize(browser()->GetSelectedTabContents()); |
637 } | 615 } |
638 | 616 |
639 void Panel::DestroyBrowser() { | 617 void Panel::DestroyBrowser() { |
640 native_panel_->DestroyPanelBrowser(); | 618 native_panel_->DestroyPanelBrowser(); |
641 } | 619 } |
OLD | NEW |