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

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

Issue 8539025: Fix Panel to always detect when a tab is added. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback changes Created 9 years, 1 month 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_browser_view.cc » ('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) 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 "content/browser/renderer_host/render_view_host.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/tab_contents/tab_contents_wrapper.h"
15 #include "chrome/browser/ui/window_sizer.h" 16 #include "chrome/browser/ui/window_sizer.h"
16 #include "chrome/browser/web_applications/web_app.h" 17 #include "chrome/browser/web_applications/web_app.h"
17 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "content/browser/renderer_host/render_view_host.h"
18 #include "content/browser/tab_contents/tab_contents.h" 20 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/common/view_messages.h" 21 #include "content/common/view_messages.h"
20 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
22 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
23 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
24 26
25 // static 27 // static
26 const Extension* Panel::GetExtensionFromBrowser(Browser* browser) { 28 const Extension* Panel::GetExtensionFromBrowser(Browser* browser) {
27 // Find the extension. When we create a panel from an extension, the extension 29 // Find the extension. When we create a panel from an extension, the extension
28 // ID is passed as the app name to the Browser. 30 // ID is passed as the app name to the Browser.
29 ExtensionService* extension_service = 31 ExtensionService* extension_service =
30 browser->GetProfile()->GetExtensionService(); 32 browser->GetProfile()->GetExtensionService();
31 return extension_service->GetExtensionById( 33 return extension_service->GetExtensionById(
32 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); 34 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false);
33 } 35 }
34 36
35 Panel::Panel(Browser* browser, const gfx::Rect& bounds) 37 Panel::Panel(Browser* browser, const gfx::Rect& bounds)
36 : min_size_(bounds.size()), 38 : min_size_(bounds.size()),
37 max_size_(bounds.size()), 39 max_size_(bounds.size()),
38 native_panel_(NULL), 40 native_panel_(NULL),
39 expansion_state_(EXPANDED), 41 expansion_state_(EXPANDED),
40 restored_height_(bounds.height()) { 42 restored_height_(bounds.height()) {
41 native_panel_ = CreateNativePanel(browser, this, bounds); 43 native_panel_ = CreateNativePanel(browser, this, bounds);
42 44 browser->tabstrip_model()->AddObserver(this);
43 registrar_.Add(this,
44 content::NOTIFICATION_TAB_ADDED,
45 content::Source<TabContentsDelegate>(browser));
46 } 45 }
47 46
48 Panel::~Panel() { 47 Panel::~Panel() {
49 // Invoked by native panel so do not access native_panel_ here. 48 // Invoked by native panel destructor. Do not access native_panel_ here.
49 }
50
51 void Panel::OnNativePanelClosed() {
52 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this);
53 manager()->Remove(this);
50 } 54 }
51 55
52 PanelManager* Panel::manager() const { 56 PanelManager* Panel::manager() const {
53 return PanelManager::GetInstance(); 57 return PanelManager::GetInstance();
54 } 58 }
55 59
56
57 const Extension* Panel::GetExtension() const { 60 const Extension* Panel::GetExtension() const {
58 return GetExtensionFromBrowser(browser()); 61 return GetExtensionFromBrowser(browser());
59 } 62 }
60 63
61 void Panel::SetPanelBounds(const gfx::Rect& bounds) { 64 void Panel::SetPanelBounds(const gfx::Rect& bounds) {
62 if (expansion_state_ == Panel::EXPANDED) 65 if (expansion_state_ == Panel::EXPANDED)
63 restored_height_ = bounds.height(); 66 restored_height_ = bounds.height();
64 67
65 native_panel_->SetPanelBounds(bounds); 68 native_panel_->SetPanelBounds(bounds);
66 } 69 }
67 70
68 void Panel::SetMaxSize(const gfx::Size& max_size) { 71 void Panel::SetMaxSize(const gfx::Size& max_size) {
69 if (max_size_ == max_size) 72 if (max_size_ == max_size)
70 return; 73 return;
71 max_size_ = max_size; 74 max_size_ = max_size;
72 75
73 // Note: |render_view_host| might be NULL if the tab has not been created. 76 // Note: |render_view_host| might be NULL if the tab has not been created.
74 // If so, we will do it when NOTIFICATION_TAB_ADDED is received. 77 // If so, we will do it when TabInsertedAt() is invoked.
75 RenderViewHost* render_view_host = GetRenderViewHost(); 78 RenderViewHost* render_view_host = GetRenderViewHost();
76 if (render_view_host) 79 if (render_view_host)
77 RequestRenderViewHostToDisableScrollbars(render_view_host); 80 RequestRenderViewHostToDisableScrollbars(render_view_host);
78 } 81 }
79 82
80 void Panel::SetExpansionState(ExpansionState new_state) { 83 void Panel::SetExpansionState(ExpansionState new_state) {
81 if (expansion_state_ == new_state) 84 if (expansion_state_ == new_state)
82 return; 85 return;
83 86
84 ExpansionState old_state = expansion_state_; 87 ExpansionState old_state = expansion_state_;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 164
162 void Panel::SetBounds(const gfx::Rect& bounds) { 165 void Panel::SetBounds(const gfx::Rect& bounds) {
163 // Ignore any SetBounds requests since the bounds are completely controlled 166 // Ignore any SetBounds requests since the bounds are completely controlled
164 // by panel manager. 167 // by panel manager.
165 } 168 }
166 169
167 // Close() may be called multiple times if the browser window is not ready to 170 // Close() may be called multiple times if the browser window is not ready to
168 // close on the first attempt. 171 // close on the first attempt.
169 void Panel::Close() { 172 void Panel::Close() {
170 native_panel_->ClosePanel(); 173 native_panel_->ClosePanel();
171
172 // TODO(dimich): Only implemented fully async on Mac. Need to update other
173 // platforms. The panel should be removed from PanelManager when and if it
174 // was actually closed. The closing can be cancelled because of onbeforeunload
175 // handler on the web page. http://crbug.com/102720
176 #if !defined(OS_MACOSX)
177 manager()->Remove(this);
178 #endif
prasadt 2011/11/11 23:08:39 I'm making this change to fix the bug mentioned in
179 } 174 }
180 175
181 void Panel::Activate() { 176 void Panel::Activate() {
182 // Make sure the panel is expanded when activated programmatically, 177 // Make sure the panel is expanded when activated programmatically,
183 // so the user input does not go into collapsed window. 178 // so the user input does not go into collapsed window.
184 SetExpansionState(Panel::EXPANDED); 179 SetExpansionState(Panel::EXPANDED);
185 native_panel_->ActivatePanel(); 180 native_panel_->ActivatePanel();
186 } 181 }
187 182
188 void Panel::Deactivate() { 183 void Panel::Deactivate() {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 void Panel::ShowAvatarBubble(TabContents* tab_contents, const gfx::Rect& rect) { 531 void Panel::ShowAvatarBubble(TabContents* tab_contents, const gfx::Rect& rect) {
537 // Panels will never show a new tab page so this should never be called. 532 // Panels will never show a new tab page so this should never be called.
538 NOTREACHED(); 533 NOTREACHED();
539 } 534 }
540 535
541 void Panel::ShowAvatarBubbleFromAvatarButton() { 536 void Panel::ShowAvatarBubbleFromAvatarButton() {
542 // Panels will never show an avatar button so this should never be called. 537 // Panels will never show an avatar button so this should never be called.
543 NOTREACHED(); 538 NOTREACHED();
544 } 539 }
545 540
541 void Panel::TabInsertedAt(TabContentsWrapper* contents,
542 int index,
543 bool foreground) {
544 DCHECK_EQ(0, index);
545 TabContents* tab_contents = contents->tab_contents();
546 EnableAutoResize(tab_contents->render_view_host());
547
548 // We also need to know when the render view host changes in order
549 // to turn on preferred size changed notifications in the new
550 // render view host.
551 registrar_.RemoveAll();
552 registrar_.Add(
553 this,
554 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
555 content::Source<TabContents>(tab_contents));
556 }
557
546 void Panel::Observe(int type, 558 void Panel::Observe(int type,
547 const content::NotificationSource& source, 559 const content::NotificationSource& source,
548 const content::NotificationDetails& details) { 560 const content::NotificationDetails& details) {
549 switch (type) { 561 DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED);
550 case content::NOTIFICATION_TAB_ADDED: 562 RenderViewHost* render_view_host =
551 // We also need to know when the render view host changes in order 563 content::Source<TabContents>(source).ptr()->render_view_host();
552 // to turn on preferred size changed notifications in the new 564 if (render_view_host)
553 // render view host. However, we cannot register for 565 EnableAutoResize(render_view_host);
554 // NOTIFICATION_TAB_CONTENTS_SWAPPED until we actually have a
555 // tab content so we register for it here.
556 registrar_.Add(
557 this,
558 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
559 content::Source<TabContents>(browser()->GetSelectedTabContents()));
560 // Fall-thru to update render view host.
561
562 case content::NOTIFICATION_TAB_CONTENTS_SWAPPED: {
563 RenderViewHost* render_view_host = GetRenderViewHost();
564 if (render_view_host) {
565 render_view_host->EnablePreferredSizeMode(
566 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
567 RequestRenderViewHostToDisableScrollbars(render_view_host);
568 }
569 break;
570 }
571 default:
572 NOTREACHED() << "Got a notification we didn't register for!";
573 break;
574 }
575 } 566 }
576 567
577 RenderViewHost* Panel::GetRenderViewHost() const { 568 RenderViewHost* Panel::GetRenderViewHost() const {
578 TabContents* tab_contents = browser()->GetSelectedTabContents(); 569 TabContents* tab_contents = browser()->GetSelectedTabContents();
579 if (!tab_contents) 570 if (!tab_contents)
580 return NULL; 571 return NULL;
581 return tab_contents->render_view_host(); 572 return tab_contents->render_view_host();
582 } 573 }
583 574
575 void Panel::EnableAutoResize(RenderViewHost* render_view_host) {
576 DCHECK(render_view_host);
577 render_view_host->EnablePreferredSizeMode(
578 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
579 RequestRenderViewHostToDisableScrollbars(render_view_host);
580 }
581
584 void Panel::RequestRenderViewHostToDisableScrollbars( 582 void Panel::RequestRenderViewHostToDisableScrollbars(
585 RenderViewHost* render_view_host) { 583 RenderViewHost* render_view_host) {
586 if (render_view_host) { 584 DCHECK(render_view_host);
587 render_view_host->DisableScrollbarsForThreshold( 585 render_view_host->DisableScrollbarsForThreshold(
588 native_panel_->ContentSizeFromWindowSize(max_size_)); 586 native_panel_->ContentSizeFromWindowSize(max_size_));
589 }
590 } 587 }
591 588
592 void Panel::OnWindowSizeAvailable() { 589 void Panel::OnWindowSizeAvailable() {
593 RequestRenderViewHostToDisableScrollbars(GetRenderViewHost()); 590 RenderViewHost* render_view_host = GetRenderViewHost();
591 if (render_view_host)
592 RequestRenderViewHostToDisableScrollbars(render_view_host);
594 } 593 }
595 594
596 Browser* Panel::browser() const { 595 Browser* Panel::browser() const {
597 return native_panel_->GetPanelBrowser(); 596 return native_panel_->GetPanelBrowser();
598 } 597 }
599 598
600 void Panel::DestroyBrowser() { 599 void Panel::DestroyBrowser() {
601 native_panel_->DestroyPanelBrowser(); 600 native_panel_->DestroyPanelBrowser();
602 } 601 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel.h ('k') | chrome/browser/ui/panels/panel_browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698