| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/gfx/path.h" | 8 #include "app/gfx/path.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
| 11 #include "chrome/browser/views/frame/browser_view.h" | 11 #include "chrome/browser/views/frame/browser_view.h" |
| 12 #include "chrome/browser/window_sizer.h" |
| 12 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 13 #include "chrome/common/notification_type.h" | 14 #include "chrome/common/notification_type.h" |
| 14 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 15 #include "views/widget/root_view.h" | 16 #include "views/widget/root_view.h" |
| 16 #include "views/window/window.h" | 17 #include "views/window/window.h" |
| 17 | 18 |
| 18 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 19 #include "app/win_util.h" | |
| 20 #include "base/win_util.h" | 20 #include "base/win_util.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 using views::View; | 23 using views::View; |
| 24 | 24 |
| 25 // All sizes are in pixels. | 25 // All sizes are in pixels. |
| 26 | 26 |
| 27 // Size of the border, along each edge. | 27 // Size of the border, along each edge. |
| 28 static const int kBorderSize = 1; | 28 static const int kBorderSize = 1; |
| 29 | 29 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 views::View* content, | 76 views::View* content, |
| 77 InfoBubbleDelegate* delegate) { | 77 InfoBubbleDelegate* delegate) { |
| 78 InfoBubble* window = new InfoBubble(); | 78 InfoBubble* window = new InfoBubble(); |
| 79 window->Init(parent, position_relative_to, content); | 79 window->Init(parent, position_relative_to, content); |
| 80 // Set the delegate before we show, on the off chance the delegate is needed | 80 // Set the delegate before we show, on the off chance the delegate is needed |
| 81 // during showing. | 81 // during showing. |
| 82 window->delegate_ = delegate; | 82 window->delegate_ = delegate; |
| 83 #if defined(OS_WIN) | 83 #if defined(OS_WIN) |
| 84 window->ShowWindow(SW_SHOW); | 84 window->ShowWindow(SW_SHOW); |
| 85 #else | 85 #else |
| 86 NOTREACHED(); | 86 static_cast<WidgetGtk*>(window)->Show(); |
| 87 #endif | 87 #endif |
| 88 return window; | 88 return window; |
| 89 } | 89 } |
| 90 | 90 |
| 91 InfoBubble::InfoBubble() | 91 InfoBubble::InfoBubble() |
| 92 : | 92 : |
| 93 #if defined(OS_LINUX) | 93 #if defined(OS_LINUX) |
| 94 WidgetGtk(TYPE_POPUP), | 94 WidgetGtk(TYPE_POPUP), |
| 95 #endif | 95 #endif |
| 96 delegate_(NULL), | 96 delegate_(NULL), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 127 set_initial_class_style( | 127 set_initial_class_style( |
| 128 (win_util::GetWinVersion() < win_util::WINVERSION_XP) ? | 128 (win_util::GetWinVersion() < win_util::WINVERSION_XP) ? |
| 129 0 : CS_DROPSHADOW); | 129 0 : CS_DROPSHADOW); |
| 130 #endif | 130 #endif |
| 131 content_view_ = CreateContentView(content); | 131 content_view_ = CreateContentView(content); |
| 132 gfx::Rect bounds = | 132 gfx::Rect bounds = |
| 133 content_view_->CalculateWindowBoundsAndAjust(position_relative_to); | 133 content_view_->CalculateWindowBoundsAndAjust(position_relative_to); |
| 134 | 134 |
| 135 #if defined(OS_WIN) | 135 #if defined(OS_WIN) |
| 136 WidgetWin::Init(parent->GetNativeWindow(), bounds, true); | 136 WidgetWin::Init(parent->GetNativeWindow(), bounds, true); |
| 137 #else |
| 138 WidgetGtk::Init(GTK_WIDGET(parent->GetNativeWindow()), bounds, true); |
| 137 #endif | 139 #endif |
| 138 SetContentsView(content_view_); | 140 SetContentsView(content_view_); |
| 139 // The preferred size may differ when parented. Ask for the bounds again | 141 // The preferred size may differ when parented. Ask for the bounds again |
| 140 // and if they differ reset the bounds. | 142 // and if they differ reset the bounds. |
| 141 gfx::Rect parented_bounds = | 143 gfx::Rect parented_bounds = |
| 142 content_view_->CalculateWindowBoundsAndAjust(position_relative_to); | 144 content_view_->CalculateWindowBoundsAndAjust(position_relative_to); |
| 143 | 145 |
| 144 if (bounds != parented_bounds) { | 146 if (bounds != parented_bounds) { |
| 145 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
| 146 SetWindowPos(NULL, parented_bounds.x(), parented_bounds.y(), | 148 SetWindowPos(NULL, parented_bounds.x(), parented_bounds.y(), |
| 147 parented_bounds.width(), parented_bounds.height(), | 149 parented_bounds.width(), parented_bounds.height(), |
| 148 SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER); | 150 SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER); |
| 149 // Invoke ChangeSize, otherwise layered window isn't updated correctly. | 151 // Invoke ChangeSize, otherwise layered window isn't updated correctly. |
| 150 ChangeSize(0, CSize(parented_bounds.width(), parented_bounds.height())); | 152 ChangeSize(0, CSize(parented_bounds.width(), parented_bounds.height())); |
| 151 #else | |
| 152 NOTIMPLEMENTED(); | |
| 153 #endif | 153 #endif |
| 154 } | 154 } |
| 155 | 155 |
| 156 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
| 157 // Register the Escape accelerator for closing. | 157 // Register the Escape accelerator for closing. |
| 158 views::FocusManager* focus_manager = | 158 views::FocusManager* focus_manager = |
| 159 views::FocusManager::GetFocusManager(GetNativeView()); | 159 views::FocusManager::GetFocusManager(GetNativeView()); |
| 160 focus_manager->RegisterAccelerator(views::Accelerator(VK_ESCAPE, false, | 160 focus_manager->RegisterAccelerator(views::Accelerator(VK_ESCAPE, false, |
| 161 false, false), | 161 false, false), |
| 162 this); | 162 this); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 if (UILayoutIsRightToLeft()) { | 247 if (UILayoutIsRightToLeft()) { |
| 248 arrow_edge_ = TOP_RIGHT; | 248 arrow_edge_ = TOP_RIGHT; |
| 249 } else { | 249 } else { |
| 250 arrow_edge_ = TOP_LEFT; | 250 arrow_edge_ = TOP_LEFT; |
| 251 } | 251 } |
| 252 AddChildView(content); | 252 AddChildView(content); |
| 253 } | 253 } |
| 254 | 254 |
| 255 gfx::Rect InfoBubble::ContentView::CalculateWindowBoundsAndAjust( | 255 gfx::Rect InfoBubble::ContentView::CalculateWindowBoundsAndAjust( |
| 256 const gfx::Rect& position_relative_to) { | 256 const gfx::Rect& position_relative_to) { |
| 257 #if defined(OS_WIN) | 257 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_provider( |
| 258 gfx::Rect monitor_bounds = win_util::GetMonitorBoundsForRect( | 258 WindowSizer::CreateDefaultMonitorInfoProvider()); |
| 259 position_relative_to); | 259 gfx::Rect monitor_bounds( |
| 260 #else | 260 monitor_provider->GetMonitorWorkAreaMatching(position_relative_to)); |
| 261 gfx::Rect monitor_bounds; | |
| 262 #endif | |
| 263 // Calculate the bounds using TOP_LEFT (the default). | 261 // Calculate the bounds using TOP_LEFT (the default). |
| 264 gfx::Rect window_bounds = CalculateWindowBounds(position_relative_to); | 262 gfx::Rect window_bounds = CalculateWindowBounds(position_relative_to); |
| 265 if (monitor_bounds.IsEmpty() || monitor_bounds.Contains(window_bounds)) | 263 if (monitor_bounds.IsEmpty() || monitor_bounds.Contains(window_bounds)) |
| 266 return window_bounds; | 264 return window_bounds; |
| 267 // Didn't fit, adjust the edge to fit as much as we can. | 265 // Didn't fit, adjust the edge to fit as much as we can. |
| 268 if (window_bounds.bottom() > monitor_bounds.bottom()) | 266 if (window_bounds.bottom() > monitor_bounds.bottom()) |
| 269 SetArrowEdge(BOTTOM_LEFT); | 267 SetArrowEdge(BOTTOM_LEFT); |
| 270 if (window_bounds.right() > monitor_bounds.right()) { | 268 if (window_bounds.right() > monitor_bounds.right()) { |
| 271 if (IsTop()) | 269 if (IsTop()) |
| 272 SetArrowEdge(TOP_RIGHT); | 270 SetArrowEdge(TOP_RIGHT); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 x -= kArrowXOffset; | 449 x -= kArrowXOffset; |
| 452 else | 450 else |
| 453 x = x + kArrowXOffset - pref.width(); | 451 x = x + kArrowXOffset - pref.width(); |
| 454 if (IsTop()) { | 452 if (IsTop()) { |
| 455 y = position_relative_to.bottom() + kArrowToContentPadding; | 453 y = position_relative_to.bottom() + kArrowToContentPadding; |
| 456 } else { | 454 } else { |
| 457 y = position_relative_to.y() - kArrowToContentPadding - pref.height(); | 455 y = position_relative_to.y() - kArrowToContentPadding - pref.height(); |
| 458 } | 456 } |
| 459 return gfx::Rect(x, y, pref.width(), pref.height()); | 457 return gfx::Rect(x, y, pref.width(), pref.height()); |
| 460 } | 458 } |
| OLD | NEW |