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/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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); | 41 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); |
42 } | 42 } |
43 | 43 |
44 Panel::Panel(Browser* browser, const gfx::Size& requested_size) | 44 Panel::Panel(Browser* browser, const gfx::Size& requested_size) |
45 : browser_(browser), | 45 : browser_(browser), |
46 initialized_(false), | 46 initialized_(false), |
47 has_temporary_layout_(false), | 47 has_temporary_layout_(false), |
48 restored_size_(requested_size), | 48 restored_size_(requested_size), |
49 auto_resizable_(false), | 49 auto_resizable_(false), |
50 draggable_(true), | 50 draggable_(true), |
| 51 layout_state_(DOCKED), |
51 expansion_state_(EXPANDED), | 52 expansion_state_(EXPANDED), |
52 old_expansion_state_(EXPANDED), | |
53 app_icon_visible_(true) { | 53 app_icon_visible_(true) { |
54 } | 54 } |
55 | 55 |
56 Panel::~Panel() { | 56 Panel::~Panel() { |
57 // Invoked by native panel destructor. Do not access native_panel_ here. | 57 // Invoked by native panel destructor. Do not access native_panel_ here. |
58 } | 58 } |
59 | 59 |
60 void Panel::Initialize(const gfx::Rect& bounds) { | 60 void Panel::Initialize(const gfx::Rect& bounds) { |
61 DCHECK(!initialized_); | 61 DCHECK(!initialized_); |
62 DCHECK(!bounds.IsEmpty()); | 62 DCHECK(!bounds.IsEmpty()); |
63 initialized_ = true; | 63 initialized_ = true; |
64 native_panel_ = CreateNativePanel(browser_, this, bounds); | 64 native_panel_ = CreateNativePanel(browser_, this, bounds); |
65 } | 65 } |
66 | 66 |
67 void Panel::OnNativePanelClosed() { | 67 void Panel::OnNativePanelClosed() { |
68 if (auto_resizable_) | 68 if (auto_resizable_) |
69 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this); | 69 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this); |
70 manager()->Remove(this); | 70 manager()->Remove(this); |
71 } | 71 } |
72 | 72 |
73 PanelManager* Panel::manager() const { | 73 PanelManager* Panel::manager() const { |
74 return PanelManager::GetInstance(); | 74 return PanelManager::GetInstance(); |
75 } | 75 } |
76 | 76 |
77 const Extension* Panel::GetExtension() const { | 77 const Extension* Panel::GetExtension() const { |
78 return GetExtensionFromBrowser(browser()); | 78 return GetExtensionFromBrowser(browser()); |
79 } | 79 } |
80 | 80 |
81 void Panel::SetPanelBounds(const gfx::Rect& bounds) { | 81 void Panel::SetPanelBounds(const gfx::Rect& bounds) { |
82 if (expansion_state_ == Panel::EXPANDED) | 82 if (layout_state_ != IN_OVERFLOW && expansion_state_ == EXPANDED) |
83 restored_size_ = bounds.size(); | 83 restored_size_ = bounds.size(); |
84 | 84 |
85 native_panel_->SetPanelBounds(bounds); | 85 native_panel_->SetPanelBounds(bounds); |
86 | 86 |
87 content::NotificationService::current()->Notify( | 87 content::NotificationService::current()->Notify( |
88 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, | 88 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, |
89 content::Source<Panel>(this), | 89 content::Source<Panel>(this), |
90 content::NotificationService::NoDetails()); | 90 content::NotificationService::NoDetails()); |
91 } | 91 } |
92 | 92 |
93 void Panel::SetPanelBoundsInstantly(const gfx::Rect& bounds) { | 93 void Panel::SetPanelBoundsInstantly(const gfx::Rect& bounds) { |
94 if (expansion_state_ == Panel::EXPANDED) | 94 if (layout_state_ != IN_OVERFLOW && expansion_state_ == EXPANDED) |
95 restored_size_ = bounds.size(); | 95 restored_size_ = bounds.size(); |
96 | 96 |
97 native_panel_->SetPanelBoundsInstantly(bounds); | 97 native_panel_->SetPanelBoundsInstantly(bounds); |
98 | 98 |
99 content::NotificationService::current()->Notify( | 99 content::NotificationService::current()->Notify( |
100 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, | 100 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, |
101 content::Source<Panel>(this), | 101 content::Source<Panel>(this), |
102 content::NotificationService::NoDetails()); | 102 content::NotificationService::NoDetails()); |
103 } | 103 } |
104 | 104 |
(...skipping 25 matching lines...) Expand all Loading... |
130 ConfigureAutoResize(browser()->GetSelectedWebContents()); | 130 ConfigureAutoResize(browser()->GetSelectedWebContents()); |
131 } | 131 } |
132 | 132 |
133 void Panel::SetAppIconVisibility(bool visible) { | 133 void Panel::SetAppIconVisibility(bool visible) { |
134 if (app_icon_visible_ == visible) | 134 if (app_icon_visible_ == visible) |
135 return; | 135 return; |
136 app_icon_visible_ = visible; | 136 app_icon_visible_ = visible; |
137 native_panel_->SetPanelAppIconVisibility(visible); | 137 native_panel_->SetPanelAppIconVisibility(visible); |
138 } | 138 } |
139 | 139 |
| 140 void Panel::SetLayoutState(LayoutState new_state) { |
| 141 if (layout_state_ == new_state) |
| 142 return; |
| 143 LayoutState old_state = layout_state_; |
| 144 layout_state_ = new_state; |
| 145 |
| 146 manager()->OnPanelLayoutStateChanged(this, old_state); |
| 147 |
| 148 content::NotificationService::current()->Notify( |
| 149 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_STATE, |
| 150 content::Source<Panel>(this), |
| 151 content::NotificationService::NoDetails()); |
| 152 } |
| 153 |
140 void Panel::SetExpansionState(ExpansionState new_state) { | 154 void Panel::SetExpansionState(ExpansionState new_state) { |
| 155 DCHECK_EQ(DOCKED, layout_state_); |
| 156 |
141 if (expansion_state_ == new_state) | 157 if (expansion_state_ == new_state) |
142 return; | 158 return; |
143 old_expansion_state_ = expansion_state_; | 159 ExpansionState old_state = expansion_state_; |
144 expansion_state_ = new_state; | 160 expansion_state_ = new_state; |
145 | 161 |
146 manager()->OnPanelExpansionStateChanged(this); | 162 manager()->OnPanelExpansionStateChanged(this, old_state); |
147 | 163 |
148 // The minimized panel should not get the focus. | 164 // The minimized panel should not get the focus. |
149 if (expansion_state_ == MINIMIZED) | 165 if (expansion_state_ == MINIMIZED && layout_state_ == DOCKED) |
150 Deactivate(); | 166 Deactivate(); |
151 | 167 |
152 content::NotificationService::current()->Notify( | 168 content::NotificationService::current()->Notify( |
153 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | 169 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, |
154 content::Source<Panel>(this), | 170 content::Source<Panel>(this), |
155 content::NotificationService::NoDetails()); | 171 content::NotificationService::NoDetails()); |
156 } | 172 } |
157 | 173 |
158 bool Panel::IsDrawingAttention() const { | 174 bool Panel::IsDrawingAttention() const { |
159 return native_panel_->IsDrawingAttention(); | 175 return native_panel_->IsDrawingAttention(); |
160 } | 176 } |
161 | 177 |
162 void Panel::FullScreenModeChanged(bool is_full_screen) { | 178 void Panel::FullScreenModeChanged(bool is_full_screen) { |
163 native_panel_->FullScreenModeChanged(is_full_screen); | 179 native_panel_->FullScreenModeChanged(is_full_screen); |
164 } | 180 } |
165 | 181 |
166 void Panel::Show() { | 182 void Panel::Show() { |
167 // Don't show panel as active if it is in overflow state. | 183 // Don't show panel as active if it is in overflow state. |
168 if (expansion_state_ == IN_OVERFLOW) | 184 if (layout_state_ == IN_OVERFLOW) |
169 ShowInactive(); | 185 ShowInactive(); |
170 else | 186 else |
171 native_panel_->ShowPanel(); | 187 native_panel_->ShowPanel(); |
172 } | 188 } |
173 | 189 |
174 void Panel::ShowInactive() { | 190 void Panel::ShowInactive() { |
175 native_panel_->ShowPanelInactive(); | 191 native_panel_->ShowPanelInactive(); |
176 } | 192 } |
177 | 193 |
178 void Panel::SetBounds(const gfx::Rect& bounds) { | 194 void Panel::SetBounds(const gfx::Rect& bounds) { |
179 // Ignore bounds position as the panel manager controls all positioning. | 195 // Ignore bounds position as the panel manager controls all positioning. |
180 manager()->ResizePanel(this, bounds.size()); | 196 manager()->ResizePanel(this, bounds.size()); |
181 } | 197 } |
182 | 198 |
183 // Close() may be called multiple times if the browser window is not ready to | 199 // Close() may be called multiple times if the browser window is not ready to |
184 // close on the first attempt. | 200 // close on the first attempt. |
185 void Panel::Close() { | 201 void Panel::Close() { |
186 native_panel_->ClosePanel(); | 202 native_panel_->ClosePanel(); |
187 } | 203 } |
188 | 204 |
189 void Panel::Activate() { | 205 void Panel::Activate() { |
190 // Make sure the panel is expanded when activated programmatically, | 206 // Make sure the panel is expanded when activated programmatically, |
191 // so the user input does not go into collapsed window. | 207 // so the user input does not go into collapsed window. |
| 208 SetLayoutState(Panel::DOCKED); |
192 SetExpansionState(Panel::EXPANDED); | 209 SetExpansionState(Panel::EXPANDED); |
193 native_panel_->ActivatePanel(); | 210 native_panel_->ActivatePanel(); |
194 } | 211 } |
195 | 212 |
196 void Panel::Deactivate() { | 213 void Panel::Deactivate() { |
197 native_panel_->DeactivatePanel(); | 214 native_panel_->DeactivatePanel(); |
198 } | 215 } |
199 | 216 |
200 bool Panel::IsActive() const { | 217 bool Panel::IsActive() const { |
201 return native_panel_->IsPanelActive(); | 218 return native_panel_->IsPanelActive(); |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 native_panel_->ContentSizeFromWindowSize(max_size_)); | 662 native_panel_->ContentSizeFromWindowSize(max_size_)); |
646 } | 663 } |
647 | 664 |
648 void Panel::OnWindowSizeAvailable() { | 665 void Panel::OnWindowSizeAvailable() { |
649 ConfigureAutoResize(browser()->GetSelectedWebContents()); | 666 ConfigureAutoResize(browser()->GetSelectedWebContents()); |
650 } | 667 } |
651 | 668 |
652 void Panel::DestroyBrowser() { | 669 void Panel::DestroyBrowser() { |
653 native_panel_->DestroyPanelBrowser(); | 670 native_panel_->DestroyPanelBrowser(); |
654 } | 671 } |
OLD | NEW |