OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/info_bubble.h" | 5 #include "chrome/browser/views/info_bubble.h" |
6 | 6 |
7 #include "base/keyboard_codes.h" | 7 #include "base/keyboard_codes.h" |
8 #include "chrome/browser/window_sizer.h" | 8 #include "chrome/browser/window_sizer.h" |
9 #include "chrome/common/notification_service.h" | 9 #include "chrome/common/notification_service.h" |
10 #include "gfx/canvas.h" | 10 #include "gfx/canvas.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
193 // BorderWidget --------------------------------------------------------------- | 193 // BorderWidget --------------------------------------------------------------- |
194 | 194 |
195 BorderWidget::BorderWidget() : border_contents_(NULL) { | 195 BorderWidget::BorderWidget() : border_contents_(NULL) { |
196 set_delete_on_destroy(false); // Our owner will free us manually. | 196 set_delete_on_destroy(false); // Our owner will free us manually. |
197 set_window_style(WS_POPUP); | 197 set_window_style(WS_POPUP); |
198 set_window_ex_style(WS_EX_TOOLWINDOW | WS_EX_LAYERED); | 198 set_window_ex_style(WS_EX_TOOLWINDOW | WS_EX_LAYERED); |
199 } | 199 } |
200 | 200 |
201 | 201 |
202 void BorderWidget::Init(HWND owner) { | 202 void BorderWidget::Init(BorderContents* border_contents, HWND owner) { |
203 DCHECK(!border_contents_); | 203 DCHECK(!border_contents_); |
204 border_contents_ = CreateBorderContents(); | 204 border_contents_ = border_contents; |
205 border_contents_->Init(); | 205 border_contents_->Init(); |
206 WidgetWin::Init(GetAncestor(owner, GA_ROOT), gfx::Rect()); | 206 WidgetWin::Init(GetAncestor(owner, GA_ROOT), gfx::Rect()); |
207 SetContentsView(border_contents_); | 207 SetContentsView(border_contents_); |
208 SetWindowPos(owner, 0, 0, 0, 0, | 208 SetWindowPos(owner, 0, 0, 0, 0, |
209 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOREDRAW); | 209 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOREDRAW); |
210 } | 210 } |
211 | 211 |
212 gfx::Rect BorderWidget::SizeAndGetBounds( | 212 gfx::Rect BorderWidget::SizeAndGetBounds( |
213 const gfx::Rect& position_relative_to, | 213 const gfx::Rect& position_relative_to, |
214 BubbleBorder::ArrowLocation arrow_location, | 214 BubbleBorder::ArrowLocation arrow_location, |
(...skipping 14 matching lines...) Expand all Loading... |
229 window_bounds.height()); | 229 window_bounds.height()); |
230 CombineRgn(window_region, window_region, contents_region, RGN_XOR); | 230 CombineRgn(window_region, window_region, contents_region, RGN_XOR); |
231 DeleteObject(contents_region); | 231 DeleteObject(contents_region); |
232 SetWindowRgn(window_region, true); | 232 SetWindowRgn(window_region, true); |
233 | 233 |
234 // Return |contents_bounds| in screen coordinates. | 234 // Return |contents_bounds| in screen coordinates. |
235 contents_bounds.Offset(window_bounds.origin()); | 235 contents_bounds.Offset(window_bounds.origin()); |
236 return contents_bounds; | 236 return contents_bounds; |
237 } | 237 } |
238 | 238 |
239 BorderContents* BorderWidget::CreateBorderContents() { | |
240 return new BorderContents(); | |
241 } | |
242 | |
243 LRESULT BorderWidget::OnMouseActivate(HWND window, | 239 LRESULT BorderWidget::OnMouseActivate(HWND window, |
244 UINT hit_test, | 240 UINT hit_test, |
245 UINT mouse_message) { | 241 UINT mouse_message) { |
246 // Never activate. | 242 // Never activate. |
247 return MA_NOACTIVATE; | 243 return MA_NOACTIVATE; |
248 } | 244 } |
249 #endif | 245 #endif |
250 | 246 |
251 // InfoBubble ----------------------------------------------------------------- | 247 // InfoBubble ----------------------------------------------------------------- |
252 | 248 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // Adding |contents| as a child has to be done before we call | 314 // Adding |contents| as a child has to be done before we call |
319 // contents->GetPreferredSize() below, since some supplied views don't | 315 // contents->GetPreferredSize() below, since some supplied views don't |
320 // actually initialize themselves until they're added to a hierarchy. | 316 // actually initialize themselves until they're added to a hierarchy. |
321 contents_view->AddChildView(contents); | 317 contents_view->AddChildView(contents); |
322 | 318 |
323 // Calculate and set the bounds for all windows and views. | 319 // Calculate and set the bounds for all windows and views. |
324 gfx::Rect window_bounds; | 320 gfx::Rect window_bounds; |
325 | 321 |
326 #if defined(OS_WIN) | 322 #if defined(OS_WIN) |
327 DCHECK(!border_.get()); | 323 DCHECK(!border_.get()); |
328 border_.reset(CreateBorderWidget()); | 324 border_.reset(new BorderWidget()); |
329 border_->Init(GetNativeView()); | 325 border_->Init(CreateBorderContents(), GetNativeView()); |
330 | 326 |
331 // Initialize and position the border window. | 327 // Initialize and position the border window. |
332 window_bounds = border_->SizeAndGetBounds(position_relative_to, | 328 window_bounds = border_->SizeAndGetBounds(position_relative_to, |
333 arrow_location, | 329 arrow_location, |
334 contents->GetPreferredSize()); | 330 contents->GetPreferredSize()); |
335 | 331 |
336 // Make |contents| take up the entire contents view. | 332 // Make |contents| take up the entire contents view. |
337 contents_view->SetLayoutManager(new views::FillLayout); | 333 contents_view->SetLayoutManager(new views::FillLayout); |
338 | 334 |
339 // Paint the background color behind the contents. | 335 // Paint the background color behind the contents. |
340 contents_view->set_background( | 336 contents_view->set_background( |
341 views::Background::CreateSolidBackground(kBackgroundColor)); | 337 views::Background::CreateSolidBackground(kBackgroundColor)); |
342 #else | 338 #else |
343 // Create a view to paint the border and background. | 339 // Create a view to paint the border and background. |
344 border_contents_ = new BorderContents; | 340 border_contents_ = CreateBorderContents(); |
345 border_contents_->Init(); | 341 border_contents_->Init(); |
346 gfx::Rect contents_bounds; | 342 gfx::Rect contents_bounds; |
347 border_contents_->SizeAndGetBounds(position_relative_to, | 343 border_contents_->SizeAndGetBounds(position_relative_to, |
348 arrow_location, false, contents->GetPreferredSize(), | 344 arrow_location, false, contents->GetPreferredSize(), |
349 &contents_bounds, &window_bounds); | 345 &contents_bounds, &window_bounds); |
350 // This new view must be added before |contents| so it will paint under it. | 346 // This new view must be added before |contents| so it will paint under it. |
351 contents_view->AddChildView(0, border_contents_); | 347 contents_view->AddChildView(0, border_contents_); |
352 | 348 |
353 // |contents_view| has no layout manager, so we have to explicitly position | 349 // |contents_view| has no layout manager, so we have to explicitly position |
354 // its children. | 350 // its children. |
(...skipping 13 matching lines...) Expand all Loading... |
368 | 364 |
369 // Show the window. | 365 // Show the window. |
370 #if defined(OS_WIN) | 366 #if defined(OS_WIN) |
371 border_->ShowWindow(SW_SHOW); | 367 border_->ShowWindow(SW_SHOW); |
372 ShowWindow(SW_SHOW); | 368 ShowWindow(SW_SHOW); |
373 #elif defined(OS_LINUX) | 369 #elif defined(OS_LINUX) |
374 views::WidgetGtk::Show(); | 370 views::WidgetGtk::Show(); |
375 #endif | 371 #endif |
376 } | 372 } |
377 | 373 |
378 #if defined(OS_WIN) | 374 BorderContents* InfoBubble::CreateBorderContents() { |
379 BorderWidget* InfoBubble::CreateBorderWidget() { | 375 return new BorderContents(); |
380 return new BorderWidget; | |
381 } | 376 } |
382 #endif | |
383 | 377 |
384 void InfoBubble::SizeToContents() { | 378 void InfoBubble::SizeToContents() { |
385 gfx::Rect window_bounds; | 379 gfx::Rect window_bounds; |
386 | 380 |
387 #if defined(OS_WIN) | 381 #if defined(OS_WIN) |
388 // Initialize and position the border window. | 382 // Initialize and position the border window. |
389 window_bounds = border_->SizeAndGetBounds(position_relative_to_, | 383 window_bounds = border_->SizeAndGetBounds(position_relative_to_, |
390 arrow_location_, | 384 arrow_location_, |
391 contents_->GetPreferredSize()); | 385 contents_->GetPreferredSize()); |
392 #else | 386 #else |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 #endif | 428 #endif |
435 } | 429 } |
436 | 430 |
437 bool InfoBubble::AcceleratorPressed(const views::Accelerator& accelerator) { | 431 bool InfoBubble::AcceleratorPressed(const views::Accelerator& accelerator) { |
438 if (!delegate_ || delegate_->CloseOnEscape()) { | 432 if (!delegate_ || delegate_->CloseOnEscape()) { |
439 Close(true); | 433 Close(true); |
440 return true; | 434 return true; |
441 } | 435 } |
442 return false; | 436 return false; |
443 } | 437 } |
OLD | NEW |