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 "base/win_util.h" | 7 #include "base/win_util.h" |
8 #include "chrome/app/theme/theme_resources.h" | 8 #include "chrome/app/theme/theme_resources.h" |
9 #include "chrome/browser/browser_window.h" | 9 #include "chrome/browser/browser_window.h" |
10 #include "chrome/browser/views/frame/browser_view.h" | 10 #include "chrome/browser/views/frame/browser_view.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_TOP_LEFT); | 101 .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_TOP_LEFT); |
102 kInfoBubbleCornerTopRight = ResourceBundle::GetSharedInstance() | 102 kInfoBubbleCornerTopRight = ResourceBundle::GetSharedInstance() |
103 .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_TOP_RIGHT); | 103 .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_TOP_RIGHT); |
104 kInfoBubbleCornerBottomLeft = ResourceBundle::GetSharedInstance() | 104 kInfoBubbleCornerBottomLeft = ResourceBundle::GetSharedInstance() |
105 .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_LEFT); | 105 .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_LEFT); |
106 kInfoBubbleCornerBottomRight = ResourceBundle::GetSharedInstance() | 106 kInfoBubbleCornerBottomRight = ResourceBundle::GetSharedInstance() |
107 .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_RIGHT); | 107 .GetBitmapNamed(IDR_INFO_BUBBLE_CORNER_BOTTOM_RIGHT); |
108 } | 108 } |
109 set_window_style(WS_POPUP | WS_CLIPCHILDREN); | 109 set_window_style(WS_POPUP | WS_CLIPCHILDREN); |
110 set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW); | 110 set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW); |
| 111 // Because we're going to change the alpha value of the layered window we |
| 112 // don't want to use the offscreen buffer provided by WidgetWin. |
| 113 SetUseLayeredBuffer(false); |
111 content_view_ = CreateContentView(content); | 114 content_view_ = CreateContentView(content); |
112 gfx::Rect bounds = content_view_-> | 115 gfx::Rect bounds = content_view_-> |
113 CalculateWindowBounds(parent_hwnd, position_relative_to); | 116 CalculateWindowBounds(parent_hwnd, position_relative_to); |
114 set_initial_class_style( | 117 set_initial_class_style( |
115 (win_util::GetWinVersion() < win_util::WINVERSION_XP) ? | 118 (win_util::GetWinVersion() < win_util::WINVERSION_XP) ? |
116 0 : CS_DROPSHADOW); | 119 0 : CS_DROPSHADOW); |
117 | 120 |
118 WidgetWin::Init(parent_hwnd, bounds, true); | 121 WidgetWin::Init(parent_hwnd, bounds, true); |
119 SetContentsView(content_view_); | 122 SetContentsView(content_view_); |
120 // The preferred size may differ when parented. Ask for the bounds again | 123 // The preferred size may differ when parented. Ask for the bounds again |
121 // and if they differ reset the bounds. | 124 // and if they differ reset the bounds. |
122 gfx::Rect parented_bounds = content_view_-> | 125 gfx::Rect parented_bounds = content_view_-> |
123 CalculateWindowBounds(parent_hwnd, position_relative_to); | 126 CalculateWindowBounds(parent_hwnd, position_relative_to); |
124 | 127 |
125 // Set our initial alpha to zero so we don't flicker at the user. This | |
126 // doesn't trigger UpdateLayeredWindow, which would explode our native | |
127 // controls. | |
128 SetLayeredAlpha(kMinimumAlpha); | |
129 | |
130 if (bounds != parented_bounds) { | 128 if (bounds != parented_bounds) { |
131 SetWindowPos(NULL, parented_bounds.x(), parented_bounds.y(), | 129 SetWindowPos(NULL, parented_bounds.x(), parented_bounds.y(), |
132 parented_bounds.width(), parented_bounds.height(), | 130 parented_bounds.width(), parented_bounds.height(), |
133 SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER); | 131 SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER); |
134 // Invoke ChangeSize, otherwise layered window isn't updated correctly. | 132 // Invoke ChangeSize, otherwise layered window isn't updated correctly. |
135 ChangeSize(0, CSize(parented_bounds.width(), parented_bounds.height())); | 133 ChangeSize(0, CSize(parented_bounds.width(), parented_bounds.height())); |
136 } | 134 } |
137 | 135 |
138 // Register the Escape accelerator for closing. | 136 // Register the Escape accelerator for closing. |
139 views::FocusManager* focus_manager = | 137 views::FocusManager* focus_manager = |
140 views::FocusManager::GetFocusManager(GetHWND()); | 138 views::FocusManager::GetFocusManager(GetHWND()); |
141 focus_manager->RegisterAccelerator(views::Accelerator(VK_ESCAPE, false, | 139 focus_manager->RegisterAccelerator(views::Accelerator(VK_ESCAPE, false, |
142 false, false), | 140 false, false), |
143 this); | 141 this); |
144 | 142 |
| 143 // Set initial alpha value of the layered window. |
| 144 SetLayeredWindowAttributes(GetHWND(), |
| 145 RGB(0xFF, 0xFF, 0xFF), |
| 146 kMinimumAlpha, |
| 147 LWA_ALPHA); |
| 148 |
145 fade_animation_.reset(new SlideAnimation(this)); | 149 fade_animation_.reset(new SlideAnimation(this)); |
146 fade_animation_->Show(); | 150 fade_animation_->Show(); |
147 } | 151 } |
148 | 152 |
149 void InfoBubble::Close() { | 153 void InfoBubble::Close() { |
150 Close(false); | 154 Close(false); |
151 } | 155 } |
152 | 156 |
153 void InfoBubble::AnimationProgressed(const Animation* animation) { | 157 void InfoBubble::AnimationProgressed(const Animation* animation) { |
154 int alpha = static_cast<int>(static_cast<double> | 158 int alpha = static_cast<int>(static_cast<double> |
155 (fade_animation_->GetCurrentValue() * (255.0 - kMinimumAlpha) + | 159 (fade_animation_->GetCurrentValue() * (255.0 - kMinimumAlpha) + |
156 kMinimumAlpha)); | 160 kMinimumAlpha)); |
157 | 161 |
158 SetLayeredWindowAttributes(GetHWND(), | 162 SetLayeredWindowAttributes(GetHWND(), |
159 RGB(0xFF, 0xFF, 0xFF), | 163 RGB(0xFF, 0xFF, 0xFF), |
160 alpha, | 164 alpha, |
161 LWA_ALPHA); | 165 LWA_ALPHA); |
162 content_view_->SchedulePaint(); | 166 // Don't need to invoke paint as SetLayeredWindowAttributes handles that for |
| 167 // us. |
163 } | 168 } |
164 | 169 |
165 bool InfoBubble::AcceleratorPressed(const views::Accelerator& accelerator) { | 170 bool InfoBubble::AcceleratorPressed(const views::Accelerator& accelerator) { |
166 DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); | 171 DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); |
167 if (!delegate_ || delegate_->CloseOnEscape()) { | 172 if (!delegate_ || delegate_->CloseOnEscape()) { |
168 Close(true); | 173 Close(true); |
169 return true; | 174 return true; |
170 } | 175 } |
171 return false; | 176 return false; |
172 } | 177 } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 x -= kArrowXOffset; | 417 x -= kArrowXOffset; |
413 else | 418 else |
414 x = x + kArrowXOffset - pref.width(); | 419 x = x + kArrowXOffset - pref.width(); |
415 if (IsTop()) { | 420 if (IsTop()) { |
416 y = position_relative_to.bottom() + kArrowToContentPadding; | 421 y = position_relative_to.bottom() + kArrowToContentPadding; |
417 } else { | 422 } else { |
418 y = position_relative_to.y() - kArrowToContentPadding - pref.height(); | 423 y = position_relative_to.y() - kArrowToContentPadding - pref.height(); |
419 } | 424 } |
420 return gfx::Rect(x, y, pref.width(), pref.height()); | 425 return gfx::Rect(x, y, pref.width(), pref.height()); |
421 } | 426 } |
OLD | NEW |