OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/extensions/extension_popup.h" | 5 #include "chrome/browser/views/extensions/extension_popup.h" |
6 | 6 |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 // The minimum is just a little larger than the size of the button itself. | 22 // The minimum is just a little larger than the size of the button itself. |
23 // The maximum is an arbitrary number that should be smaller than most screens. | 23 // The maximum is an arbitrary number that should be smaller than most screens. |
24 const int ExtensionPopup::kMinWidth = 25; | 24 const int ExtensionPopup::kMinWidth = 25; |
25 const int ExtensionPopup::kMinHeight = 25; | 25 const int ExtensionPopup::kMinHeight = 25; |
26 const int ExtensionPopup::kMaxWidth = 800; | 26 const int ExtensionPopup::kMaxWidth = 800; |
27 const int ExtensionPopup::kMaxHeight = 600; | 27 const int ExtensionPopup::kMaxHeight = 600; |
28 | 28 |
29 ExtensionPopup::ExtensionPopup(ExtensionHost* host, | 29 ExtensionPopup::ExtensionPopup(ExtensionHost* host, |
30 Widget* frame, | 30 Widget* frame, |
31 const gfx::Rect& relative_to, | 31 const gfx::Rect& relative_to, |
32 BubbleBorder::ArrowLocation arrow_location) | 32 BubbleBorder::ArrowLocation arrow_location, |
33 bool activate_on_show) | |
33 : BrowserBubble(host->view(), | 34 : BrowserBubble(host->view(), |
34 frame, | 35 frame, |
35 gfx::Point()), | 36 gfx::Point()), |
36 relative_to_(relative_to), | 37 relative_to_(relative_to), |
37 extension_host_(host) { | 38 extension_host_(host), |
39 activate_on_show_(activate_on_show) { | |
38 host->view()->SetContainer(this); | 40 host->view()->SetContainer(this); |
39 registrar_.Add(this, | 41 registrar_.Add(this, |
40 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, | 42 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, |
41 Source<Profile>(host->profile())); | 43 Source<Profile>(host->profile())); |
42 | 44 |
43 // TODO(erikkay) Some of this border code is derived from InfoBubble. | 45 // TODO(erikkay) Some of this border code is derived from InfoBubble. |
44 // We should see if we can unify these classes. | 46 // We should see if we can unify these classes. |
45 | 47 |
46 border_widget_ = Widget::CreatePopupWidget(Widget::Transparent, | 48 border_widget_ = Widget::CreatePopupWidget(Widget::Transparent, |
47 Widget::NotAcceptEvents, | 49 Widget::NotAcceptEvents, |
48 Widget::DeleteOnDestroy); | 50 Widget::DeleteOnDestroy); |
49 gfx::NativeView native_window = frame->GetNativeView(); | 51 gfx::NativeView native_window = frame->GetNativeView(); |
50 border_widget_->Init(native_window, bounds()); | 52 border_widget_->Init(native_window, bounds()); |
51 | 53 |
52 border_ = new BubbleBorder; | 54 border_ = new BubbleBorder; |
53 border_->set_arrow_location(arrow_location); | 55 border_->set_arrow_location(arrow_location); |
54 | 56 |
55 border_view_ = new views::View; | 57 border_view_ = new views::View; |
56 border_view_->set_background(new BubbleBackground(border_)); | 58 border_view_->set_background(new BubbleBackground(border_)); |
57 border_view_->set_border(border_); | 59 border_view_->set_border(border_); |
58 border_widget_->SetContentsView(border_view_); | 60 border_widget_->SetContentsView(border_view_); |
61 | |
62 // Ensure that the popup contents are always displayed ontop of the border | |
63 // widget. | |
64 border_widget_->MoveAbove(popup_); | |
rafaelw
2009/12/08 00:25:54
Can you explain what's going on here? Why is the b
Jeff Timanus
2009/12/08 01:05:38
Sorry for not making this clear. The issue with t
| |
59 } | 65 } |
60 | 66 |
61 ExtensionPopup::~ExtensionPopup() { | 67 ExtensionPopup::~ExtensionPopup() { |
62 // The widget is set to delete on destroy, so no leak here. | 68 // The widget is set to delete on destroy, so no leak here. |
63 border_widget_->Close(); | 69 border_widget_->Close(); |
64 } | 70 } |
65 | 71 |
66 void ExtensionPopup::Hide() { | 72 void ExtensionPopup::Hide() { |
67 BrowserBubble::Hide(); | 73 BrowserBubble::Hide(); |
68 border_widget_->Hide(); | 74 border_widget_->Hide(); |
69 } | 75 } |
70 | 76 |
71 void ExtensionPopup::Show() { | 77 void ExtensionPopup::Show(bool activate) { |
72 if (visible()) | 78 if (visible()) |
73 return; | 79 return; |
74 | 80 |
75 #if defined(OS_WIN) | 81 #if defined(OS_WIN) |
76 frame_->GetWindow()->DisableInactiveRendering(); | 82 frame_->GetWindow()->DisableInactiveRendering(); |
77 #endif | 83 #endif |
78 | 84 |
79 ResizeToView(); | 85 ResizeToView(); |
80 | 86 |
81 // Show the border first, then the popup overlaid on top. | 87 // Show the border first, then the popup overlaid on top. |
82 border_widget_->Show(); | 88 border_widget_->Show(); |
83 BrowserBubble::Show(true); | 89 BrowserBubble::Show(activate); |
84 } | 90 } |
85 | 91 |
86 void ExtensionPopup::ResizeToView() { | 92 void ExtensionPopup::ResizeToView() { |
87 // We'll be sizing ourselves to this size shortly, but wait until we | 93 // We'll be sizing ourselves to this size shortly, but wait until we |
88 // know our position to do it. | 94 // know our position to do it. |
89 gfx::Size new_size = view()->size(); | 95 gfx::Size new_size = view()->size(); |
90 | 96 |
91 // The rounded corners cut off more of the view than the border insets claim. | 97 // The rounded corners cut off more of the view than the border insets claim. |
92 // Since we can't clip the ExtensionView's corners, we need to increase the | 98 // Since we can't clip the ExtensionView's corners, we need to increase the |
93 // inset by half the corner radius as well as lying about the size of the | 99 // inset by half the corner radius as well as lying about the size of the |
(...skipping 17 matching lines...) Expand all Loading... | |
111 SetBounds(origin.x(), origin.y(), new_size.width(), new_size.height()); | 117 SetBounds(origin.x(), origin.y(), new_size.width(), new_size.height()); |
112 } | 118 } |
113 | 119 |
114 void ExtensionPopup::Observe(NotificationType type, | 120 void ExtensionPopup::Observe(NotificationType type, |
115 const NotificationSource& source, | 121 const NotificationSource& source, |
116 const NotificationDetails& details) { | 122 const NotificationDetails& details) { |
117 if (type == NotificationType::EXTENSION_HOST_DID_STOP_LOADING) { | 123 if (type == NotificationType::EXTENSION_HOST_DID_STOP_LOADING) { |
118 // Once we receive did stop loading, the content will be complete and | 124 // Once we receive did stop loading, the content will be complete and |
119 // the width will have been computed. Now it's safe to show. | 125 // the width will have been computed. Now it's safe to show. |
120 if (extension_host_.get() == Details<ExtensionHost>(details).ptr()) | 126 if (extension_host_.get() == Details<ExtensionHost>(details).ptr()) |
121 Show(); | 127 Show(activate_on_show_); |
122 } else { | 128 } else { |
123 NOTREACHED() << L"Received unexpected notification"; | 129 NOTREACHED() << L"Received unexpected notification"; |
124 } | 130 } |
125 } | 131 } |
126 | 132 |
127 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { | 133 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { |
128 // Constrain the size to popup min/max. | 134 // Constrain the size to popup min/max. |
129 gfx::Size sz = view->GetPreferredSize(); | 135 gfx::Size sz = view->GetPreferredSize(); |
130 view->SetBounds(view->x(), view->y(), | 136 view->SetBounds(view->x(), view->y(), |
131 std::max(kMinWidth, std::min(kMaxWidth, sz.width())), | 137 std::max(kMinWidth, std::min(kMaxWidth, sz.width())), |
132 std::max(kMinHeight, std::min(kMaxHeight, sz.height()))); | 138 std::max(kMinHeight, std::min(kMaxHeight, sz.height()))); |
133 | 139 |
134 ResizeToView(); | 140 ResizeToView(); |
135 } | 141 } |
136 | 142 |
137 // static | 143 // static |
138 ExtensionPopup* ExtensionPopup::Show( | 144 ExtensionPopup* ExtensionPopup::Show( |
139 const GURL& url, Browser* browser, | 145 const GURL& url, Browser* browser, |
140 const gfx::Rect& relative_to, | 146 const gfx::Rect& relative_to, |
141 BubbleBorder::ArrowLocation arrow_location) { | 147 BubbleBorder::ArrowLocation arrow_location, |
148 bool activate_on_show) { | |
142 ExtensionProcessManager* manager = | 149 ExtensionProcessManager* manager = |
143 browser->profile()->GetExtensionProcessManager(); | 150 browser->profile()->GetExtensionProcessManager(); |
144 DCHECK(manager); | 151 DCHECK(manager); |
145 if (!manager) | 152 if (!manager) |
146 return NULL; | 153 return NULL; |
147 | 154 |
148 ExtensionHost* host = manager->CreatePopup(url, browser); | 155 ExtensionHost* host = manager->CreatePopup(url, browser); |
149 views::Widget* frame = BrowserView::GetBrowserViewForNativeWindow( | 156 views::Widget* frame = BrowserView::GetBrowserViewForNativeWindow( |
150 browser->window()->GetNativeHandle())->GetWidget(); | 157 browser->window()->GetNativeHandle())->GetWidget(); |
151 ExtensionPopup* popup = new ExtensionPopup(host, frame, relative_to, | 158 ExtensionPopup* popup = new ExtensionPopup(host, frame, relative_to, |
152 arrow_location); | 159 arrow_location, activate_on_show); |
153 | 160 |
154 // If the host had somehow finished loading, then we'd miss the notification | 161 // If the host had somehow finished loading, then we'd miss the notification |
155 // and not show. This seems to happen in single-process mode. | 162 // and not show. This seems to happen in single-process mode. |
156 if (host->did_stop_loading()) | 163 if (host->did_stop_loading()) |
157 popup->Show(); | 164 popup->Show(activate_on_show); |
158 | 165 |
159 return popup; | 166 return popup; |
160 } | 167 } |
OLD | NEW |