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" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 // ID is passed as the app name to the Browser. | 29 // ID is passed as the app name to the Browser. |
30 ExtensionService* extension_service = | 30 ExtensionService* extension_service = |
31 browser->GetProfile()->GetExtensionService(); | 31 browser->GetProfile()->GetExtensionService(); |
32 return extension_service->GetExtensionById( | 32 return extension_service->GetExtensionById( |
33 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); | 33 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); |
34 } | 34 } |
35 | 35 |
36 Panel::Panel(Browser* browser, const gfx::Rect& bounds) | 36 Panel::Panel(Browser* browser, const gfx::Rect& bounds) |
37 : min_size_(bounds.size()), | 37 : min_size_(bounds.size()), |
38 max_size_(bounds.size()), | 38 max_size_(bounds.size()), |
39 auto_resizable_(false), | |
39 native_panel_(NULL), | 40 native_panel_(NULL), |
40 expansion_state_(EXPANDED), | 41 expansion_state_(EXPANDED), |
41 restored_height_(bounds.height()) { | 42 restored_height_(bounds.height()) { |
42 native_panel_ = CreateNativePanel(browser, this, bounds); | 43 native_panel_ = CreateNativePanel(browser, this, bounds); |
43 browser->tabstrip_model()->AddObserver(this); | |
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::OnNativePanelClosed() { | 50 void Panel::OnNativePanelClosed() { |
51 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this); | 51 if (auto_resizable_) |
52 native_panel_->GetPanelBrowser()->tabstrip_model()->RemoveObserver(this); | |
52 manager()->Remove(this); | 53 manager()->Remove(this); |
53 } | 54 } |
54 | 55 |
55 PanelManager* Panel::manager() const { | 56 PanelManager* Panel::manager() const { |
56 return PanelManager::GetInstance(); | 57 return PanelManager::GetInstance(); |
57 } | 58 } |
58 | 59 |
59 const Extension* Panel::GetExtension() const { | 60 const Extension* Panel::GetExtension() const { |
60 return GetExtensionFromBrowser(browser()); | 61 return GetExtensionFromBrowser(browser()); |
61 } | 62 } |
62 | 63 |
63 void Panel::SetPanelBounds(const gfx::Rect& bounds) { | 64 void Panel::SetPanelBounds(const gfx::Rect& bounds) { |
64 if (expansion_state_ == Panel::EXPANDED) | 65 if (expansion_state_ == Panel::EXPANDED) |
65 restored_height_ = bounds.height(); | 66 restored_height_ = bounds.height(); |
66 | 67 |
67 native_panel_->SetPanelBounds(bounds); | 68 native_panel_->SetPanelBounds(bounds); |
68 | 69 |
69 content::NotificationService::current()->Notify( | 70 content::NotificationService::current()->Notify( |
70 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, | 71 chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS, |
71 content::Source<Panel>(this), | 72 content::Source<Panel>(this), |
72 content::NotificationService::NoDetails()); | 73 content::NotificationService::NoDetails()); |
73 } | 74 } |
74 | 75 |
75 void Panel::SetMaxSize(const gfx::Size& max_size) { | 76 void Panel::SetMaxSize(const gfx::Size& max_size) { |
76 if (max_size_ == max_size) | 77 if (max_size_ == max_size) |
77 return; | 78 return; |
78 max_size_ = max_size; | 79 max_size_ = max_size; |
79 | 80 |
80 // Note: |render_view_host| might be NULL if the tab has not been created. | 81 if (auto_resizable_) { |
jianli
2011/11/18 23:03:32
Is this needed now? SetMaxSize seems to be always
jennb
2011/11/18 23:26:00
I'm going to leave this rather than assume the max
| |
81 // If so, we will do it when TabInsertedAt() is invoked. | 82 // Note: |render_view_host| might be NULL if the tab has not been created. |
82 RenderViewHost* render_view_host = GetRenderViewHost(); | 83 // If so, we will do it when TabInsertedAt() is invoked. |
83 if (render_view_host) | 84 RenderViewHost* render_view_host = GetRenderViewHost(); |
84 RequestRenderViewHostToDisableScrollbars(render_view_host); | 85 if (render_view_host) |
86 RequestRenderViewHostToDisableScrollbars(render_view_host); | |
87 } | |
88 } | |
89 | |
90 void Panel::SetMinSize(const gfx::Size& min_size) { | |
91 if (min_size_ == min_size) | |
92 return; | |
93 min_size_ = min_size; | |
94 } | |
95 | |
96 void Panel::SetAutoResizable(bool resizable) { | |
97 if (auto_resizable_ == resizable) | |
98 return; | |
99 | |
100 auto_resizable_ = resizable; | |
101 if (auto_resizable_) { | |
102 browser()->tabstrip_model()->AddObserver(this); | |
103 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
104 if (tab_contents) | |
105 SetUpAutoResize(tab_contents); | |
106 } else { | |
107 browser()->tabstrip_model()->RemoveObserver(this); | |
108 registrar_.RemoveAll(); | |
109 } | |
85 } | 110 } |
86 | 111 |
87 void Panel::SetExpansionState(ExpansionState new_state) { | 112 void Panel::SetExpansionState(ExpansionState new_state) { |
88 if (expansion_state_ == new_state) | 113 if (expansion_state_ == new_state) |
89 return; | 114 return; |
90 | 115 |
91 ExpansionState old_state = expansion_state_; | 116 ExpansionState old_state = expansion_state_; |
92 expansion_state_ = new_state; | 117 expansion_state_ = new_state; |
93 | 118 |
94 int height; | 119 int height; |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 NOTIMPLEMENTED(); | 545 NOTIMPLEMENTED(); |
521 } | 546 } |
522 | 547 |
523 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { | 548 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { |
524 NOTIMPLEMENTED(); | 549 NOTIMPLEMENTED(); |
525 } | 550 } |
526 #endif | 551 #endif |
527 | 552 |
528 void Panel::UpdatePreferredSize(TabContents* tab_contents, | 553 void Panel::UpdatePreferredSize(TabContents* tab_contents, |
529 const gfx::Size& pref_size) { | 554 const gfx::Size& pref_size) { |
530 return manager()->OnPreferredWindowSizeChanged(this, | 555 if (auto_resizable_) { |
531 native_panel_->WindowSizeFromContentSize(pref_size)); | 556 return manager()->OnPreferredWindowSizeChanged(this, |
557 native_panel_->WindowSizeFromContentSize(pref_size)); | |
558 } | |
532 } | 559 } |
533 | 560 |
534 void Panel::ShowAvatarBubble(TabContents* tab_contents, const gfx::Rect& rect) { | 561 void Panel::ShowAvatarBubble(TabContents* tab_contents, const gfx::Rect& rect) { |
535 // Panels will never show a new tab page so this should never be called. | 562 // Panels will never show a new tab page so this should never be called. |
536 NOTREACHED(); | 563 NOTREACHED(); |
537 } | 564 } |
538 | 565 |
539 void Panel::ShowAvatarBubbleFromAvatarButton() { | 566 void Panel::ShowAvatarBubbleFromAvatarButton() { |
540 // Panels will never show an avatar button so this should never be called. | 567 // Panels will never show an avatar button so this should never be called. |
541 NOTREACHED(); | 568 NOTREACHED(); |
542 } | 569 } |
543 | 570 |
544 void Panel::TabInsertedAt(TabContentsWrapper* contents, | 571 void Panel::TabInsertedAt(TabContentsWrapper* contents, |
545 int index, | 572 int index, |
546 bool foreground) { | 573 bool foreground) { |
547 DCHECK_EQ(0, index); | 574 if (auto_resizable_) { |
548 TabContents* tab_contents = contents->tab_contents(); | 575 DCHECK_EQ(0, index); |
549 EnableAutoResize(tab_contents->render_view_host()); | 576 SetUpAutoResize(contents->tab_contents()); |
577 } | |
578 } | |
579 | |
580 void Panel::SetUpAutoResize(TabContents* tab_contents) { | |
581 DCHECK(tab_contents); | |
582 RenderViewHost* render_view_host = tab_contents->render_view_host(); | |
583 if (render_view_host) | |
584 EnableRendererAutoResize(render_view_host); | |
550 | 585 |
551 // We also need to know when the render view host changes in order | 586 // We also need to know when the render view host changes in order |
552 // to turn on preferred size changed notifications in the new | 587 // to turn on preferred size changed notifications in the new |
553 // render view host. | 588 // render view host. |
554 registrar_.RemoveAll(); // Stop notifications for previous contents, if any. | 589 registrar_.RemoveAll(); // Stop notifications for previous contents, if any. |
555 registrar_.Add( | 590 registrar_.Add( |
556 this, | 591 this, |
557 content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 592 content::NOTIFICATION_TAB_CONTENTS_SWAPPED, |
558 content::Source<TabContents>(tab_contents)); | 593 content::Source<TabContents>(tab_contents)); |
559 } | 594 } |
560 | 595 |
jennb
2011/11/18 22:31:05
Oops. Will delete this extra line.
| |
596 | |
561 void Panel::Observe(int type, | 597 void Panel::Observe(int type, |
562 const content::NotificationSource& source, | 598 const content::NotificationSource& source, |
563 const content::NotificationDetails& details) { | 599 const content::NotificationDetails& details) { |
564 DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED); | 600 if (auto_resizable_) { |
565 RenderViewHost* render_view_host = | 601 DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED); |
566 content::Source<TabContents>(source).ptr()->render_view_host(); | 602 RenderViewHost* render_view_host = |
567 if (render_view_host) | 603 content::Source<TabContents>(source).ptr()->render_view_host(); |
568 EnableAutoResize(render_view_host); | 604 if (render_view_host) |
605 EnableRendererAutoResize(render_view_host); | |
606 } | |
569 } | 607 } |
570 | 608 |
571 RenderViewHost* Panel::GetRenderViewHost() const { | 609 RenderViewHost* Panel::GetRenderViewHost() const { |
572 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 610 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
573 if (!tab_contents) | 611 if (!tab_contents) |
574 return NULL; | 612 return NULL; |
575 return tab_contents->render_view_host(); | 613 return tab_contents->render_view_host(); |
576 } | 614 } |
577 | 615 |
578 void Panel::EnableAutoResize(RenderViewHost* render_view_host) { | 616 void Panel::EnableRendererAutoResize(RenderViewHost* render_view_host) { |
617 DCHECK(auto_resizable_); | |
579 DCHECK(render_view_host); | 618 DCHECK(render_view_host); |
580 render_view_host->EnablePreferredSizeMode(); | 619 render_view_host->EnablePreferredSizeMode(); |
581 RequestRenderViewHostToDisableScrollbars(render_view_host); | 620 RequestRenderViewHostToDisableScrollbars(render_view_host); |
582 } | 621 } |
583 | 622 |
584 void Panel::RequestRenderViewHostToDisableScrollbars( | 623 void Panel::RequestRenderViewHostToDisableScrollbars( |
585 RenderViewHost* render_view_host) { | 624 RenderViewHost* render_view_host) { |
625 DCHECK(auto_resizable_); | |
586 DCHECK(render_view_host); | 626 DCHECK(render_view_host); |
587 render_view_host->DisableScrollbarsForThreshold( | 627 render_view_host->DisableScrollbarsForThreshold( |
588 native_panel_->ContentSizeFromWindowSize(max_size_)); | 628 native_panel_->ContentSizeFromWindowSize(max_size_)); |
589 } | 629 } |
590 | 630 |
591 void Panel::OnWindowSizeAvailable() { | 631 void Panel::OnWindowSizeAvailable() { |
592 RenderViewHost* render_view_host = GetRenderViewHost(); | 632 if (auto_resizable_) { |
593 if (render_view_host) | 633 RenderViewHost* render_view_host = GetRenderViewHost(); |
594 RequestRenderViewHostToDisableScrollbars(render_view_host); | 634 if (render_view_host) |
635 RequestRenderViewHostToDisableScrollbars(render_view_host); | |
636 } | |
595 } | 637 } |
596 | 638 |
597 Browser* Panel::browser() const { | 639 Browser* Panel::browser() const { |
598 return native_panel_->GetPanelBrowser(); | 640 return native_panel_->GetPanelBrowser(); |
599 } | 641 } |
600 | 642 |
601 void Panel::DestroyBrowser() { | 643 void Panel::DestroyBrowser() { |
602 native_panel_->DestroyPanelBrowser(); | 644 native_panel_->DestroyPanelBrowser(); |
603 } | 645 } |
OLD | NEW |