Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/ui/panels/panel.cc

Issue 9560002: Cleanup to keep panel from manipulating its panel strip assignment directly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed final nits Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/panels/panel.h ('k') | chrome/browser/ui/panels/panel_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 void Panel::Initialize(const gfx::Rect& bounds) { 61 void Panel::Initialize(const gfx::Rect& bounds) {
62 DCHECK(!initialized_); 62 DCHECK(!initialized_);
63 DCHECK(!bounds.IsEmpty()); 63 DCHECK(!bounds.IsEmpty());
64 initialized_ = true; 64 initialized_ = true;
65 native_panel_ = CreateNativePanel(browser_, this, bounds); 65 native_panel_ = CreateNativePanel(browser_, this, bounds);
66 } 66 }
67 67
68 void Panel::OnNativePanelClosed() { 68 void Panel::OnNativePanelClosed() {
69 if (auto_resizable_) 69 if (auto_resizable_)
70 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this); 70 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this);
71 panel_strip_->RemovePanel(this);
72 manager()->OnPanelClosed(this); 71 manager()->OnPanelClosed(this);
72 DCHECK(!panel_strip_);
73 } 73 }
74 74
75 PanelManager* Panel::manager() const { 75 PanelManager* Panel::manager() const {
76 return PanelManager::GetInstance(); 76 return PanelManager::GetInstance();
77 } 77 }
78 78
79 bool Panel::draggable() const { 79 bool Panel::draggable() const {
80 return panel_strip()->CanDragPanel(this); 80 return panel_strip_ && panel_strip_->CanDragPanel(this);
81 } 81 }
82 82
83 const Extension* Panel::GetExtension() const { 83 const Extension* Panel::GetExtension() const {
84 return GetExtensionFromBrowser(browser()); 84 return GetExtensionFromBrowser(browser());
85 } 85 }
86 86
87 // TODO(jennb): do not update restored_size here as there's no knowledge 87 // TODO(jennb): do not update restored_size here as there's no knowledge
88 // at this point whether the bounds change is due to the content window 88 // at this point whether the bounds change is due to the content window
89 // being resized vs a change in current display bounds, e.g. from overflow 89 // being resized vs a change in current display bounds, e.g. from overflow
90 // size change. Change this when refactoring panel resize logic. 90 // size change. Change this when refactoring panel resize logic.
91 void Panel::SetPanelBounds(const gfx::Rect& bounds) { 91 void Panel::SetPanelBounds(const gfx::Rect& bounds) {
92 if (panel_strip_->type() == PanelStrip::DOCKED && 92 if (panel_strip_ && panel_strip_->type() == PanelStrip::DOCKED &&
93 expansion_state_ == Panel::EXPANDED) 93 expansion_state_ == Panel::EXPANDED)
94 restored_size_ = bounds.size(); 94 restored_size_ = bounds.size();
95 95
96 native_panel_->SetPanelBounds(bounds); 96 native_panel_->SetPanelBounds(bounds);
97 97
98 content::NotificationService::current()->Notify( 98 content::NotificationService::current()->Notify(
99 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, 99 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS,
100 content::Source<Panel>(this), 100 content::Source<Panel>(this),
101 content::NotificationService::NoDetails()); 101 content::NotificationService::NoDetails());
102 } 102 }
103 103
104 void Panel::SetPanelBoundsInstantly(const gfx::Rect& bounds) { 104 void Panel::SetPanelBoundsInstantly(const gfx::Rect& bounds) {
105 if (panel_strip_->type() == PanelStrip::DOCKED && 105 if (panel_strip_ && panel_strip_->type() == PanelStrip::DOCKED &&
106 expansion_state_ == Panel::EXPANDED) 106 expansion_state_ == Panel::EXPANDED)
107 restored_size_ = bounds.size(); 107 restored_size_ = bounds.size();
108 108
109 native_panel_->SetPanelBoundsInstantly(bounds); 109 native_panel_->SetPanelBoundsInstantly(bounds);
110 110
111 content::NotificationService::current()->Notify( 111 content::NotificationService::current()->Notify(
112 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, 112 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS,
113 content::Source<Panel>(this), 113 content::Source<Panel>(this),
114 content::NotificationService::NoDetails()); 114 content::NotificationService::NoDetails());
115 } 115 }
(...skipping 26 matching lines...) Expand all
142 ConfigureAutoResize(browser()->GetSelectedWebContents()); 142 ConfigureAutoResize(browser()->GetSelectedWebContents());
143 } 143 }
144 144
145 void Panel::SetAppIconVisibility(bool visible) { 145 void Panel::SetAppIconVisibility(bool visible) {
146 if (app_icon_visible_ == visible) 146 if (app_icon_visible_ == visible)
147 return; 147 return;
148 app_icon_visible_ = visible; 148 app_icon_visible_ = visible;
149 native_panel_->SetPanelAppIconVisibility(visible); 149 native_panel_->SetPanelAppIconVisibility(visible);
150 } 150 }
151 151
152 void Panel::MoveToStrip(PanelStrip* new_strip) {
153 DCHECK_NE(panel_strip_, new_strip);
154 if (panel_strip_)
155 panel_strip_->RemovePanel(this);
156
157 panel_strip_ = new_strip;
158 panel_strip_->AddPanel(this);
159
160 content::NotificationService::current()->Notify(
161 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE,
162 content::Source<Panel>(this),
163 content::NotificationService::NoDetails());
164 }
165
166 void Panel::SetExpansionState(ExpansionState new_state) { 152 void Panel::SetExpansionState(ExpansionState new_state) {
167 if (expansion_state_ == new_state) 153 if (expansion_state_ == new_state)
168 return; 154 return;
169 old_expansion_state_ = expansion_state_; 155 old_expansion_state_ = expansion_state_;
170 expansion_state_ = new_state; 156 expansion_state_ = new_state;
171 157
172 manager()->OnPanelExpansionStateChanged(this); 158 manager()->OnPanelExpansionStateChanged(this);
173 159
174 // The minimized panel should not get the focus. 160 // The minimized panel should not get the focus.
175 if (expansion_state_ == MINIMIZED) 161 if (expansion_state_ == MINIMIZED)
176 Deactivate(); 162 Deactivate();
177 163
178 content::NotificationService::current()->Notify( 164 content::NotificationService::current()->Notify(
179 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, 165 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE,
180 content::Source<Panel>(this), 166 content::Source<Panel>(this),
181 content::NotificationService::NoDetails()); 167 content::NotificationService::NoDetails());
182 } 168 }
183 169
184 bool Panel::IsDrawingAttention() const { 170 bool Panel::IsDrawingAttention() const {
185 return native_panel_->IsDrawingAttention(); 171 return native_panel_->IsDrawingAttention();
186 } 172 }
187 173
188 void Panel::FullScreenModeChanged(bool is_full_screen) { 174 void Panel::FullScreenModeChanged(bool is_full_screen) {
189 native_panel_->FullScreenModeChanged(is_full_screen); 175 native_panel_->FullScreenModeChanged(is_full_screen);
190 } 176 }
191 177
192 void Panel::Show() { 178 void Panel::Show() {
193 if (manager()->is_full_screen()) 179 if (manager()->is_full_screen() || !panel_strip_)
194 return; 180 return;
195 181
196 if (panel_strip_->CanShowPanelAsActive(this)) 182 if (panel_strip_->CanShowPanelAsActive(this))
197 native_panel_->ShowPanel(); 183 native_panel_->ShowPanel();
198 else 184 else
199 ShowInactive(); 185 ShowInactive();
200 } 186 }
201 187
202 void Panel::ShowInactive() { 188 void Panel::ShowInactive() {
203 if (manager()->is_full_screen()) 189 if (manager()->is_full_screen() || !panel_strip_)
204 return; 190 return;
205 191
206 native_panel_->ShowPanelInactive(); 192 native_panel_->ShowPanelInactive();
207 } 193 }
208 194
209 void Panel::SetBounds(const gfx::Rect& bounds) { 195 void Panel::SetBounds(const gfx::Rect& bounds) {
210 // Ignore bounds position as the panel manager controls all positioning. 196 // Ignore bounds position as the panel manager controls all positioning.
211 manager()->ResizePanel(this, bounds.size()); 197 manager()->ResizePanel(this, bounds.size());
212 } 198 }
213 199
214 // Close() may be called multiple times if the browser window is not ready to 200 // Close() may be called multiple times if the browser window is not ready to
215 // close on the first attempt. 201 // close on the first attempt.
216 void Panel::Close() { 202 void Panel::Close() {
217 native_panel_->ClosePanel(); 203 native_panel_->ClosePanel();
218 } 204 }
219 205
220 void Panel::Activate() { 206 void Panel::Activate() {
207 if (!panel_strip_)
208 return;
209
221 panel_strip_->ActivatePanel(this); 210 panel_strip_->ActivatePanel(this);
222 native_panel_->ActivatePanel(); 211 native_panel_->ActivatePanel();
223 } 212 }
224 213
225 void Panel::Deactivate() { 214 void Panel::Deactivate() {
226 native_panel_->DeactivatePanel(); 215 native_panel_->DeactivatePanel();
227 } 216 }
228 217
229 bool Panel::IsActive() const { 218 bool Panel::IsActive() const {
230 return native_panel_->IsPanelActive(); 219 return native_panel_->IsPanelActive();
231 } 220 }
232 221
233 void Panel::FlashFrame(bool flash) { 222 void Panel::FlashFrame(bool flash) {
234 if (IsDrawingAttention() == flash) 223 if (IsDrawingAttention() == flash || !panel_strip_)
235 return; 224 return;
236 225
237 // Don't draw attention for an active panel. 226 // Don't draw attention for an active panel.
238 if (flash && IsActive()) 227 if (flash && IsActive())
239 return; 228 return;
240 229
241 native_panel_->DrawAttention(flash); 230 native_panel_->DrawAttention(flash);
242 panel_strip_->OnPanelAttentionStateChanged(this); 231 panel_strip_->OnPanelAttentionStateChanged(this);
243 } 232 }
244 233
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 void Panel::EnsureFullyVisible() { 298 void Panel::EnsureFullyVisible() {
310 native_panel_->EnsurePanelFullyVisible(); 299 native_panel_->EnsurePanelFullyVisible();
311 } 300 }
312 301
313 bool Panel::IsMaximized() const { 302 bool Panel::IsMaximized() const {
314 // Size of panels is managed by PanelManager, they are never 'zoomed'. 303 // Size of panels is managed by PanelManager, they are never 'zoomed'.
315 return false; 304 return false;
316 } 305 }
317 306
318 bool Panel::IsMinimized() const { 307 bool Panel::IsMinimized() const {
319 PanelStrip::Type strip_type = panel_strip_->type(); 308 return !panel_strip_ || panel_strip()->IsPanelMinimized(this);
320 return strip_type == PanelStrip::IN_OVERFLOW ||
321 (strip_type == PanelStrip::DOCKED && expansion_state_ != EXPANDED);
322 } 309 }
323 310
324 void Panel::Maximize() { 311 void Panel::Maximize() {
325 Restore(); 312 Restore();
326 } 313 }
327 314
328 void Panel::Minimize() { 315 void Panel::Minimize() {
329 panel_strip_->MinimizePanel(this); 316 if (panel_strip_)
317 panel_strip_->MinimizePanel(this);
330 } 318 }
331 319
332 void Panel::Restore() { 320 void Panel::Restore() {
333 panel_strip_->RestorePanel(this); 321 if (panel_strip_)
322 panel_strip_->RestorePanel(this);
334 } 323 }
335 324
336 void Panel::EnterFullscreen( 325 void Panel::EnterFullscreen(
337 const GURL& url, FullscreenExitBubbleType type) { 326 const GURL& url, FullscreenExitBubbleType type) {
338 NOTIMPLEMENTED(); 327 NOTIMPLEMENTED();
339 } 328 }
340 329
341 void Panel::ExitFullscreen() { 330 void Panel::ExitFullscreen() {
342 NOTIMPLEMENTED(); 331 NOTIMPLEMENTED();
343 } 332 }
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 native_panel_->ContentSizeFromWindowSize(max_size_)); 674 native_panel_->ContentSizeFromWindowSize(max_size_));
686 } 675 }
687 676
688 void Panel::OnWindowSizeAvailable() { 677 void Panel::OnWindowSizeAvailable() {
689 ConfigureAutoResize(browser()->GetSelectedWebContents()); 678 ConfigureAutoResize(browser()->GetSelectedWebContents());
690 } 679 }
691 680
692 void Panel::DestroyBrowser() { 681 void Panel::DestroyBrowser() {
693 native_panel_->DestroyPanelBrowser(); 682 native_panel_->DestroyPanelBrowser();
694 } 683 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel.h ('k') | chrome/browser/ui/panels/panel_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698