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