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/dropdown_bar_host.h" | 5 #include "chrome/browser/views/dropdown_bar_host.h" |
6 | 6 |
7 #include "app/keyboard_codes.h" | 7 #include "app/keyboard_codes.h" |
8 #include "app/slide_animation.h" | 8 #include "app/slide_animation.h" |
9 #include "base/scoped_handle.h" | |
10 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/view_ids.h" | 10 #include "chrome/browser/ui/view_ids.h" |
12 #include "chrome/browser/ui/views/dropdown_bar_view.h" | 11 #include "chrome/browser/ui/views/dropdown_bar_view.h" |
13 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
14 #include "gfx/path.h" | 13 #include "gfx/path.h" |
15 #include "gfx/scrollbar_size.h" | 14 #include "gfx/scrollbar_size.h" |
16 #include "views/focus/external_focus_tracker.h" | 15 #include "views/focus/external_focus_tracker.h" |
17 #include "views/focus/view_storage.h" | 16 #include "views/focus/view_storage.h" |
18 #include "views/widget/widget.h" | 17 #include "views/widget/widget.h" |
19 | 18 |
20 #if defined(OS_LINUX) | 19 #if defined(OS_WIN) |
| 20 #include "base/win/scoped_gdi_object.h" |
| 21 #elif defined(OS_LINUX) |
21 #include "app/scoped_handle_gtk.h" | 22 #include "app/scoped_handle_gtk.h" |
22 #endif | 23 #endif |
23 | 24 |
| 25 namespace { |
| 26 |
| 27 #if defined(OS_WIN) |
| 28 typedef base::win::ScopedRegion ScopedPlatformRegion; |
| 29 #elif defined(OS_LINUX) |
| 30 typedef ScopedRegion ScopedPlatformRegion; |
| 31 #endif |
| 32 |
| 33 } // namespace |
| 34 |
24 using gfx::Path; | 35 using gfx::Path; |
25 | 36 |
26 // static | 37 // static |
27 bool DropdownBarHost::disable_animations_during_testing_ = false; | 38 bool DropdownBarHost::disable_animations_during_testing_ = false; |
28 | 39 |
29 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
30 // DropdownBarHost, public: | 41 // DropdownBarHost, public: |
31 | 42 |
32 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) | 43 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) |
33 : browser_view_(browser_view), | 44 : browser_view_(browser_view), |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // Find the largest x and y value in the polygon. | 216 // Find the largest x and y value in the polygon. |
206 int max_x = 0, max_y = 0; | 217 int max_x = 0, max_y = 0; |
207 for (size_t i = 0; i < arraysize(polygon); i++) { | 218 for (size_t i = 0; i < arraysize(polygon); i++) { |
208 max_x = std::max(max_x, static_cast<int>(polygon[i].x)); | 219 max_x = std::max(max_x, static_cast<int>(polygon[i].x)); |
209 max_y = std::max(max_y, static_cast<int>(polygon[i].y)); | 220 max_y = std::max(max_y, static_cast<int>(polygon[i].y)); |
210 } | 221 } |
211 | 222 |
212 // We then create the polygon and use SetWindowRgn to force the window to draw | 223 // We then create the polygon and use SetWindowRgn to force the window to draw |
213 // only within that area. This region may get reduced in size below. | 224 // only within that area. This region may get reduced in size below. |
214 Path path(polygon, arraysize(polygon)); | 225 Path path(polygon, arraysize(polygon)); |
215 ScopedRegion region(path.CreateNativeRegion()); | 226 ScopedPlatformRegion region(path.CreateNativeRegion()); |
216 | |
217 // Are we animating? | 227 // Are we animating? |
218 if (animation_offset() > 0) { | 228 if (animation_offset() > 0) { |
219 // The animation happens in two steps: First, we clip the window and then in | 229 // The animation happens in two steps: First, we clip the window and then in |
220 // GetWidgetPosition we offset the window position so that it still looks | 230 // GetWidgetPosition we offset the window position so that it still looks |
221 // attached to the toolbar as it grows. We clip the window by creating a | 231 // attached to the toolbar as it grows. We clip the window by creating a |
222 // rectangle region (that gradually increases as the animation progresses) | 232 // rectangle region (that gradually increases as the animation progresses) |
223 // and find the intersection between the two regions using CombineRgn. | 233 // and find the intersection between the two regions using CombineRgn. |
224 | 234 |
225 // |y| shrinks as the animation progresses from the height of the view down | 235 // |y| shrinks as the animation progresses from the height of the view down |
226 // to 0 (and reverses when closing). | 236 // to 0 (and reverses when closing). |
227 int y = animation_offset(); | 237 int y = animation_offset(); |
228 // |y| shrinking means the animation (visible) region gets larger. In other | 238 // |y| shrinking means the animation (visible) region gets larger. In other |
229 // words: the rectangle grows upward (when the widget is opening). | 239 // words: the rectangle grows upward (when the widget is opening). |
230 Path animation_path; | 240 Path animation_path; |
231 SkRect animation_rect = { SkIntToScalar(0), SkIntToScalar(y), | 241 SkRect animation_rect = { SkIntToScalar(0), SkIntToScalar(y), |
232 SkIntToScalar(max_x), SkIntToScalar(max_y) }; | 242 SkIntToScalar(max_x), SkIntToScalar(max_y) }; |
233 animation_path.addRect(animation_rect); | 243 animation_path.addRect(animation_rect); |
234 ScopedRegion animation_region(animation_path.CreateNativeRegion()); | 244 ScopedPlatformRegion animation_region( |
| 245 animation_path.CreateNativeRegion()); |
235 region.Set(Path::IntersectRegions(animation_region.Get(), region.Get())); | 246 region.Set(Path::IntersectRegions(animation_region.Get(), region.Get())); |
236 | 247 |
237 // Next, we need to increase the region a little bit to account for the | 248 // Next, we need to increase the region a little bit to account for the |
238 // curved edges that the view will draw to make it look like grows out of | 249 // curved edges that the view will draw to make it look like grows out of |
239 // the toolbar. | 250 // the toolbar. |
240 Path::Point left_curve[] = { | 251 Path::Point left_curve[] = { |
241 {0, y+0}, {0, y+1}, {2, y+3}, {2, y+0}, {0, y+0} | 252 {0, y+0}, {0, y+1}, {2, y+3}, {2, y+0}, {0, y+0} |
242 }; | 253 }; |
243 Path::Point right_curve[] = { | 254 Path::Point right_curve[] = { |
244 {w+3, y+3}, {w+6, y+0}, {w+3, y+0}, {w+3, y+3} | 255 {w+3, y+3}, {w+6, y+0}, {w+3, y+0}, {w+3, y+3} |
245 }; | 256 }; |
246 | 257 |
247 // Combine the region for the curve on the left with our main region. | 258 // Combine the region for the curve on the left with our main region. |
248 Path left_path(left_curve, arraysize(left_curve)); | 259 Path left_path(left_curve, arraysize(left_curve)); |
249 ScopedRegion r(left_path.CreateNativeRegion()); | 260 ScopedPlatformRegion r(left_path.CreateNativeRegion()); |
250 region.Set(Path::CombineRegions(r.Get(), region.Get())); | 261 region.Set(Path::CombineRegions(r.Get(), region.Get())); |
251 | 262 |
252 // Combine the region for the curve on the right with our main region. | 263 // Combine the region for the curve on the right with our main region. |
253 Path right_path(right_curve, arraysize(right_curve)); | 264 Path right_path(right_curve, arraysize(right_curve)); |
254 region.Set(Path::CombineRegions(r.Get(), region.Get())); | 265 region.Set(Path::CombineRegions(r.Get(), region.Get())); |
255 } | 266 } |
256 | 267 |
257 // Now see if we need to truncate the region because parts of it obscures | 268 // Now see if we need to truncate the region because parts of it obscures |
258 // the main window border. | 269 // the main window border. |
259 gfx::Rect widget_bounds; | 270 gfx::Rect widget_bounds; |
(...skipping 17 matching lines...) Expand all Loading... |
277 exclude[1].y = 0; | 288 exclude[1].y = 0; |
278 | 289 |
279 exclude[2].x = max_x; // Bottom right corner. | 290 exclude[2].x = max_x; // Bottom right corner. |
280 exclude[2].y = max_y; | 291 exclude[2].y = max_y; |
281 | 292 |
282 exclude[3].x = max_x - difference; // Bottom left corner. | 293 exclude[3].x = max_x - difference; // Bottom left corner. |
283 exclude[3].y = max_y; | 294 exclude[3].y = max_y; |
284 | 295 |
285 // Subtract this region from the original region. | 296 // Subtract this region from the original region. |
286 gfx::Path exclude_path(exclude, arraysize(exclude)); | 297 gfx::Path exclude_path(exclude, arraysize(exclude)); |
287 ScopedRegion exclude_region(exclude_path.CreateNativeRegion()); | 298 ScopedPlatformRegion exclude_region(exclude_path.CreateNativeRegion()); |
288 region.Set(Path::SubtractRegion(region.Get(), exclude_region.Get())); | 299 region.Set(Path::SubtractRegion(region.Get(), exclude_region.Get())); |
289 } | 300 } |
290 | 301 |
291 // Window takes ownership of the region. | 302 // Window takes ownership of the region. |
292 host()->SetShape(region.release()); | 303 host()->SetShape(region.release()); |
293 } | 304 } |
294 | 305 |
295 void DropdownBarHost::RegisterAccelerators() { | 306 void DropdownBarHost::RegisterAccelerators() { |
296 DCHECK(!esc_accel_target_registered_); | 307 DCHECK(!esc_accel_target_registered_); |
297 views::Accelerator escape(app::VKEY_ESCAPE, false, false, false); | 308 views::Accelerator escape(app::VKEY_ESCAPE, false, false, false); |
298 focus_manager_->RegisterAccelerator(escape, this); | 309 focus_manager_->RegisterAccelerator(escape, this); |
299 esc_accel_target_registered_ = true; | 310 esc_accel_target_registered_ = true; |
300 } | 311 } |
301 | 312 |
302 void DropdownBarHost::UnregisterAccelerators() { | 313 void DropdownBarHost::UnregisterAccelerators() { |
303 DCHECK(esc_accel_target_registered_); | 314 DCHECK(esc_accel_target_registered_); |
304 views::Accelerator escape(app::VKEY_ESCAPE, false, false, false); | 315 views::Accelerator escape(app::VKEY_ESCAPE, false, false, false); |
305 focus_manager_->UnregisterAccelerator(escape, this); | 316 focus_manager_->UnregisterAccelerator(escape, this); |
306 esc_accel_target_registered_ = false; | 317 esc_accel_target_registered_ = false; |
307 } | 318 } |
OLD | NEW |