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/views/browser_bubble.h" | 5 #include "chrome/browser/ui/views/browser_bubble.h" |
6 | 6 |
7 #include "chrome/browser/ui/views/bubble/border_contents.h" | 7 #include "chrome/browser/ui/views/bubble/border_contents.h" |
8 #include "chrome/browser/ui/views/bubble/border_widget_win.h" | 8 #include "chrome/browser/ui/views/bubble/border_widget_win.h" |
9 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
10 #include "views/widget/root_view.h" | 10 #include "views/widget/root_view.h" |
11 #include "views/widget/widget_win.h" | 11 #include "views/widget/widget_win.h" |
12 #include "views/window/window.h" | 12 #include "views/window/window.h" |
13 | 13 |
14 class BubbleWidget : public views::WidgetWin { | 14 class BubbleWidget : public views::WidgetWin { |
15 public: | 15 public: |
16 explicit BubbleWidget(BrowserBubble* bubble) | 16 explicit BubbleWidget(BrowserBubble* bubble) |
17 : bubble_(bubble), | 17 : views::WidgetWin(new views::Widget), |
| 18 bubble_(bubble), |
18 border_widget_(new BorderWidgetWin) { | 19 border_widget_(new BorderWidgetWin) { |
19 set_window_style(WS_POPUP | WS_CLIPCHILDREN); | 20 set_window_style(WS_POPUP | WS_CLIPCHILDREN); |
20 set_window_ex_style(WS_EX_TOOLWINDOW); | 21 set_window_ex_style(WS_EX_TOOLWINDOW); |
21 } | 22 } |
22 | 23 |
23 void ShowAndActivate(bool activate) { | 24 void ShowAndActivate(bool activate) { |
24 // Show the border first, then the popup overlaid on top. | 25 // Show the border first, then the popup overlaid on top. |
25 border_widget_->Show(); | 26 border_widget_->Show(); |
26 if (activate) | 27 if (activate) |
27 ShowWindow(SW_SHOW); | 28 ShowWindow(SW_SHOW); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 private: | 102 private: |
102 BrowserBubble* bubble_; | 103 BrowserBubble* bubble_; |
103 BorderWidgetWin* border_widget_; | 104 BorderWidgetWin* border_widget_; |
104 | 105 |
105 DISALLOW_COPY_AND_ASSIGN(BubbleWidget); | 106 DISALLOW_COPY_AND_ASSIGN(BubbleWidget); |
106 }; | 107 }; |
107 | 108 |
108 void BrowserBubble::InitPopup(const gfx::Insets& content_margins) { | 109 void BrowserBubble::InitPopup(const gfx::Insets& content_margins) { |
109 // popup_ is a Widget, but we need to do some WidgetWin stuff first, then | 110 // popup_ is a Widget, but we need to do some WidgetWin stuff first, then |
110 // we'll assign it into popup_. | 111 // we'll assign it into popup_. |
111 BubbleWidget* pop = new BubbleWidget(this); | 112 BubbleWidget* bubble_widget = new BubbleWidget(this); |
112 popup_ = pop; | |
113 | 113 |
114 BorderWidgetWin* border_widget = pop->border_widget(); | 114 BorderWidgetWin* border_widget = bubble_widget->border_widget(); |
115 border_widget->InitBorderWidgetWin(new BorderContents, | 115 border_widget->InitBorderWidgetWin(new BorderContents, |
116 frame_->GetNativeView()); | 116 frame_->GetNativeView()); |
117 border_widget->border_contents()->set_content_margins(content_margins); | 117 border_widget->border_contents()->set_content_margins(content_margins); |
118 | 118 |
| 119 popup_ = bubble_widget->GetWidget(); |
119 // We make the BorderWidgetWin the owner of the Bubble HWND, so that the | 120 // We make the BorderWidgetWin the owner of the Bubble HWND, so that the |
120 // latter is displayed on top of the former. | 121 // latter is displayed on top of the former. |
121 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 122 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 123 params.native_widget = bubble_widget; |
122 params.parent = border_widget->GetNativeView(); | 124 params.parent = border_widget->GetNativeView(); |
123 popup_->Init(params); | 125 popup_->Init(params); |
124 popup_->SetContentsView(view_); | 126 popup_->SetContentsView(view_); |
125 | 127 |
126 ResizeToView(); | 128 ResizeToView(); |
127 Reposition(); | 129 Reposition(); |
128 AttachToBrowser(); | 130 AttachToBrowser(); |
129 } | 131 } |
130 | 132 |
131 void BrowserBubble::MovePopup(int x, int y, int w, int h) { | |
132 views::WidgetWin* pop = static_cast<views::WidgetWin*>(popup_); | |
133 pop->SetBounds(gfx::Rect(x, y, w, h)); | |
134 } | |
135 | |
136 void BrowserBubble::Show(bool activate) { | 133 void BrowserBubble::Show(bool activate) { |
137 if (visible_) | 134 if (!popup_->IsVisible()) { |
138 return; | 135 static_cast<BubbleWidget*>(popup_->native_widget())->ShowAndActivate( |
139 BubbleWidget* pop = static_cast<BubbleWidget*>(popup_); | 136 activate); |
140 pop->ShowAndActivate(activate); | 137 } |
141 visible_ = true; | |
142 } | 138 } |
143 | 139 |
144 void BrowserBubble::Hide() { | 140 void BrowserBubble::Hide() { |
145 if (!visible_) | 141 if (popup_->IsVisible()) |
146 return; | 142 static_cast<BubbleWidget*>(popup_->native_widget())->Hide(); |
147 views::WidgetWin* pop = static_cast<views::WidgetWin*>(popup_); | |
148 pop->Hide(); | |
149 visible_ = false; | |
150 } | 143 } |
151 | 144 |
152 void BrowserBubble::ResizeToView() { | 145 void BrowserBubble::ResizeToView() { |
153 BorderWidgetWin* border_widget = | 146 BorderWidgetWin* border_widget = |
154 static_cast<BubbleWidget*>(popup_)->border_widget(); | 147 static_cast<BubbleWidget*>(popup_->native_widget())->border_widget(); |
155 | 148 |
156 gfx::Rect window_bounds; | 149 gfx::Rect window_bounds; |
157 window_bounds = border_widget->SizeAndGetBounds(GetAbsoluteRelativeTo(), | 150 window_bounds = border_widget->SizeAndGetBounds(GetAbsoluteRelativeTo(), |
158 arrow_location_, view_->size()); | 151 arrow_location_, view_->size()); |
159 | 152 |
160 SetAbsoluteBounds(window_bounds); | 153 SetAbsoluteBounds(window_bounds); |
161 } | 154 } |
OLD | NEW |