OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/tabs/tab.h" | 5 #include "chrome/browser/ui/views/tabs/tab.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 explicit TabCloseButton(Tab* tab) | 245 explicit TabCloseButton(Tab* tab) |
246 : views::ImageButton(tab), | 246 : views::ImageButton(tab), |
247 tab_(tab) { | 247 tab_(tab) { |
248 SetEventTargeter( | 248 SetEventTargeter( |
249 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 249 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
250 } | 250 } |
251 | 251 |
252 virtual ~TabCloseButton() {} | 252 virtual ~TabCloseButton() {} |
253 | 253 |
254 // views::View: | 254 // views::View: |
255 virtual View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE { | |
256 if (!views::UsePointBasedTargeting(rect)) | |
257 return View::GetEventHandlerForRect(rect); | |
258 | |
259 // Ignore the padding set on the button. | |
260 gfx::Rect contents_bounds = GetContentsBounds(); | |
261 contents_bounds.set_x(GetMirroredXForRect(contents_bounds)); | |
262 | |
263 // Include the padding in hit-test for touch events. | |
264 if (aura::Env::GetInstance()->is_touch_down()) | |
265 contents_bounds = GetLocalBounds(); | |
266 | |
267 return contents_bounds.Intersects(rect) ? this : parent(); | |
268 } | |
269 | |
270 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE { | 255 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE { |
271 // Tab close button has no children, so tooltip handler should be the same | 256 // Tab close button has no children, so tooltip handler should be the same |
272 // as the event handler. | 257 // as the event handler. |
273 // In addition, a hit test has to be performed for the point (as | 258 // In addition, a hit test has to be performed for the point (as |
274 // GetTooltipHandlerForPoint() is responsible for it). | 259 // GetTooltipHandlerForPoint() is responsible for it). |
275 if (!HitTestPoint(point)) | 260 if (!HitTestPoint(point)) |
276 return NULL; | 261 return NULL; |
277 return GetEventHandlerForPoint(point); | 262 return GetEventHandlerForPoint(point); |
278 } | 263 } |
279 | 264 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 int top_overflow = tab_bounds.y() - button_bounds.y(); | 315 int top_overflow = tab_bounds.y() - button_bounds.y(); |
331 int bottom_overflow = button_bounds.bottom() - tab_bounds.bottom(); | 316 int bottom_overflow = button_bounds.bottom() - tab_bounds.bottom(); |
332 if (top_overflow > 0) | 317 if (top_overflow > 0) |
333 button_bounds.set_y(tab_bounds.y()); | 318 button_bounds.set_y(tab_bounds.y()); |
334 else if (bottom_overflow > 0) | 319 else if (bottom_overflow > 0) |
335 button_bounds.set_height(button_bounds.height() - bottom_overflow); | 320 button_bounds.set_height(button_bounds.height() - bottom_overflow); |
336 | 321 |
337 return button_bounds; | 322 return button_bounds; |
338 } | 323 } |
339 | 324 |
| 325 // views::ViewTargeterDelegate: |
| 326 virtual View* TargetForRect(View* root, const gfx::Rect& rect) OVERRIDE { |
| 327 CHECK_EQ(root, this); |
| 328 |
| 329 if (!views::UsePointBasedTargeting(rect)) |
| 330 return ViewTargeterDelegate::TargetForRect(root, rect); |
| 331 |
| 332 // Ignore the padding set on the button. |
| 333 gfx::Rect contents_bounds = GetContentsBounds(); |
| 334 contents_bounds.set_x(GetMirroredXForRect(contents_bounds)); |
| 335 |
| 336 // Include the padding in hit-test for touch events. |
| 337 if (aura::Env::GetInstance()->is_touch_down()) |
| 338 contents_bounds = GetLocalBounds(); |
| 339 |
| 340 return contents_bounds.Intersects(rect) ? this : parent(); |
| 341 } |
| 342 |
340 // views:MaskedTargeterDelegate: | 343 // views:MaskedTargeterDelegate: |
341 virtual bool GetHitTestMask(gfx::Path* mask) const OVERRIDE { | 344 virtual bool GetHitTestMask(gfx::Path* mask) const OVERRIDE { |
342 DCHECK(mask); | 345 DCHECK(mask); |
343 mask->reset(); | 346 mask->reset(); |
344 | 347 |
345 // The parent tab may be partially occluded by another tab if we are | 348 // The parent tab may be partially occluded by another tab if we are |
346 // in stacked tab mode, which means that the tab close button may also | 349 // in stacked tab mode, which means that the tab close button may also |
347 // be partially occluded. Define the hit test mask of the tab close | 350 // be partially occluded. Define the hit test mask of the tab close |
348 // button to be the intersection of the parent tab's visible bounds | 351 // button to be the intersection of the parent tab's visible bounds |
349 // and the bounds of the tab close button. | 352 // and the bounds of the tab close button. |
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 const gfx::ImageSkia& image) { | 1652 const gfx::ImageSkia& image) { |
1650 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1653 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
1651 ImageCacheEntry entry; | 1654 ImageCacheEntry entry; |
1652 entry.resource_id = resource_id; | 1655 entry.resource_id = resource_id; |
1653 entry.scale_factor = scale_factor; | 1656 entry.scale_factor = scale_factor; |
1654 entry.image = image; | 1657 entry.image = image; |
1655 image_cache_->push_front(entry); | 1658 image_cache_->push_front(entry); |
1656 if (image_cache_->size() > kMaxImageCacheSize) | 1659 if (image_cache_->size() > kMaxImageCacheSize) |
1657 image_cache_->pop_back(); | 1660 image_cache_->pop_back(); |
1658 } | 1661 } |
OLD | NEW |