| 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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // button is hidden behind another tab. | 412 // button is hidden behind another tab. |
| 413 gfx::Path tab_mask; | 413 gfx::Path tab_mask; |
| 414 tab_->GetHitTestMask(source, &tab_mask); | 414 tab_->GetHitTestMask(source, &tab_mask); |
| 415 | 415 |
| 416 gfx::Rect button_bounds(GetContentsBounds()); | 416 gfx::Rect button_bounds(GetContentsBounds()); |
| 417 button_bounds.set_x(GetMirroredXForRect(button_bounds)); | 417 button_bounds.set_x(GetMirroredXForRect(button_bounds)); |
| 418 gfx::RectF tab_bounds_f(gfx::SkRectToRectF(tab_mask.getBounds())); | 418 gfx::RectF tab_bounds_f(gfx::SkRectToRectF(tab_mask.getBounds())); |
| 419 views::View::ConvertRectToTarget(tab_, this, &tab_bounds_f); | 419 views::View::ConvertRectToTarget(tab_, this, &tab_bounds_f); |
| 420 gfx::Rect tab_bounds = gfx::ToEnclosingRect(tab_bounds_f); | 420 gfx::Rect tab_bounds = gfx::ToEnclosingRect(tab_bounds_f); |
| 421 | 421 |
| 422 // If the button is hidden behind another tab, the hit test mask is empty. | 422 // If either the top or bottom of the tab close button is clipped, |
| 423 // Otherwise set the hit test mask to be the contents bounds. | 423 // do not consider these regions to be part of the button's bounds. |
| 424 int top_overflow = tab_bounds.y() - button_bounds.y(); |
| 425 int bottom_overflow = button_bounds.bottom() - tab_bounds.bottom(); |
| 426 if (top_overflow > 0) |
| 427 button_bounds.set_y(tab_bounds.y()); |
| 428 else if (bottom_overflow > 0) |
| 429 button_bounds.set_height(button_bounds.height() - bottom_overflow); |
| 430 |
| 431 // If the hit test request is in response to a gesture, |path| should be |
| 432 // empty unless the entire tab close button is visible to the user. Hit |
| 433 // test requests in response to a mouse event should always set |path| |
| 434 // to be the visible portion of the tab close button, even if it is |
| 435 // partially hidden behind another tab. |
| 424 path->reset(); | 436 path->reset(); |
| 425 if (tab_bounds.Intersects(button_bounds)) { | 437 gfx::Rect intersection(gfx::IntersectRects(tab_bounds, button_bounds)); |
| 426 // Include the padding in the hit test mask for touch events. | 438 if (!intersection.IsEmpty()) { |
| 427 if (source == HIT_TEST_SOURCE_TOUCH) | 439 // TODO(tdanderson): Consider always returning the intersection if |
| 428 button_bounds = GetLocalBounds(); | 440 // the non-rectangular shape of the tabs can be accounted for. |
| 441 if (source == HIT_TEST_SOURCE_TOUCH && |
| 442 !tab_bounds.Contains(button_bounds)) |
| 443 return; |
| 429 | 444 |
| 430 // TODO: this isn't quite right, really need to intersect the two regions. | 445 path->addRect(RectToSkRect(intersection)); |
| 431 path->addRect(RectToSkRect(button_bounds)); | |
| 432 } | 446 } |
| 433 } | 447 } |
| 434 | 448 |
| 435 virtual const char* GetClassName() const OVERRIDE { | 449 virtual const char* GetClassName() const OVERRIDE { |
| 436 return kTabCloseButtonName; | 450 return kTabCloseButtonName; |
| 437 } | 451 } |
| 438 | 452 |
| 439 private: | 453 private: |
| 440 Tab* tab_; | 454 Tab* tab_; |
| 441 | 455 |
| (...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 const gfx::ImageSkia& image) { | 1753 const gfx::ImageSkia& image) { |
| 1740 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1754 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
| 1741 ImageCacheEntry entry; | 1755 ImageCacheEntry entry; |
| 1742 entry.resource_id = resource_id; | 1756 entry.resource_id = resource_id; |
| 1743 entry.scale_factor = scale_factor; | 1757 entry.scale_factor = scale_factor; |
| 1744 entry.image = image; | 1758 entry.image = image; |
| 1745 image_cache_->push_front(entry); | 1759 image_cache_->push_front(entry); |
| 1746 if (image_cache_->size() > kMaxImageCacheSize) | 1760 if (image_cache_->size() > kMaxImageCacheSize) |
| 1747 image_cache_->pop_back(); | 1761 image_cache_->pop_back(); |
| 1748 } | 1762 } |
| OLD | NEW |