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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // button is hidden behind another tab. | 415 // button is hidden behind another tab. |
416 gfx::Path tab_mask; | 416 gfx::Path tab_mask; |
417 tab_->GetHitTestMask(source, &tab_mask); | 417 tab_->GetHitTestMask(source, &tab_mask); |
418 | 418 |
419 gfx::Rect button_bounds(GetContentsBounds()); | 419 gfx::Rect button_bounds(GetContentsBounds()); |
420 button_bounds.set_x(GetMirroredXForRect(button_bounds)); | 420 button_bounds.set_x(GetMirroredXForRect(button_bounds)); |
421 gfx::RectF tab_bounds_f(gfx::SkRectToRectF(tab_mask.getBounds())); | 421 gfx::RectF tab_bounds_f(gfx::SkRectToRectF(tab_mask.getBounds())); |
422 views::View::ConvertRectToTarget(tab_, this, &tab_bounds_f); | 422 views::View::ConvertRectToTarget(tab_, this, &tab_bounds_f); |
423 gfx::Rect tab_bounds = gfx::ToEnclosingRect(tab_bounds_f); | 423 gfx::Rect tab_bounds = gfx::ToEnclosingRect(tab_bounds_f); |
424 | 424 |
425 // If the button is hidden behind another tab, the hit test mask is empty. | 425 // If either the top or bottom of the tab close button is clipped, |
426 // Otherwise set the hit test mask to be the contents bounds. | 426 // do not consider these regions to be part of the button's bounds. |
| 427 int top_overflow = tab_bounds.y() - button_bounds.y(); |
| 428 int bottom_overflow = button_bounds.bottom() - tab_bounds.bottom(); |
| 429 if (top_overflow > 0) |
| 430 button_bounds.set_y(tab_bounds.y()); |
| 431 else if (bottom_overflow > 0) |
| 432 button_bounds.set_height(button_bounds.height() - bottom_overflow); |
| 433 |
| 434 // If the hit test request is in response to a gesture, |path| should be |
| 435 // empty unless the entire tab close button is visible to the user. Hit |
| 436 // test requests in response to a mouse event should always set |path| |
| 437 // to be the visible portion of the tab close button, even if it is |
| 438 // partially hidden behind another tab. |
427 path->reset(); | 439 path->reset(); |
428 if (tab_bounds.Contains(button_bounds)) { | 440 gfx::Rect intersection(gfx::IntersectRects(tab_bounds, button_bounds)); |
429 // Include the padding in the hit test mask for touch events. | 441 if (!intersection.IsEmpty()) { |
430 if (source == HIT_TEST_SOURCE_TOUCH) | 442 // TODO(tdanderson): Consider always returning the intersection if |
431 button_bounds = GetLocalBounds(); | 443 // the non-rectangular shape of the tabs can be accounted for. |
| 444 if (source == HIT_TEST_SOURCE_TOUCH && |
| 445 !tab_bounds.Contains(button_bounds)) |
| 446 return; |
432 | 447 |
433 path->addRect(RectToSkRect(button_bounds)); | 448 path->addRect(RectToSkRect(intersection)); |
434 } | 449 } |
435 } | 450 } |
436 | 451 |
437 virtual const char* GetClassName() const OVERRIDE { | 452 virtual const char* GetClassName() const OVERRIDE { |
438 return kTabCloseButtonName; | 453 return kTabCloseButtonName; |
439 } | 454 } |
440 | 455 |
441 private: | 456 private: |
442 Tab* tab_; | 457 Tab* tab_; |
443 | 458 |
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 const gfx::ImageSkia& image) { | 1788 const gfx::ImageSkia& image) { |
1774 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1789 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
1775 ImageCacheEntry entry; | 1790 ImageCacheEntry entry; |
1776 entry.resource_id = resource_id; | 1791 entry.resource_id = resource_id; |
1777 entry.scale_factor = scale_factor; | 1792 entry.scale_factor = scale_factor; |
1778 entry.image = image; | 1793 entry.image = image; |
1779 image_cache_->push_front(entry); | 1794 image_cache_->push_front(entry); |
1780 if (image_cache_->size() > kMaxImageCacheSize) | 1795 if (image_cache_->size() > kMaxImageCacheSize) |
1781 image_cache_->pop_back(); | 1796 image_cache_->pop_back(); |
1782 } | 1797 } |
OLD | NEW |