Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 147623004: Tab close buttons can only be targeted with touch if the whole button is visible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TODO added Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_strip.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // TODO(tdanderson): Consider always returning the intersection if
432 // the non-rectangular shape of the tabs can be accounted for.
424 path->reset(); 433 path->reset();
425 if (tab_bounds.Intersects(button_bounds)) { 434 gfx::Rect intersection(gfx::IntersectRects(tab_bounds, button_bounds));
426 // Include the padding in the hit test mask for touch events. 435 if (intersection.IsEmpty()) {
427 if (source == HIT_TEST_SOURCE_TOUCH) 436 // Do not set a hit test mask if the button is completely hidden.
428 button_bounds = GetLocalBounds(); 437 return;
438 } else if (source == HIT_TEST_SOURCE_TOUCH) {
sky 2014/02/06 00:24:10 nit: style guide says no else after a return.
tdanderson 2014/02/06 01:19:55 Done.
439 // If the hit test request is from touch, only return a hit test mask
440 // if the button is completely visible to the user.
441 if (!tab_bounds.Contains(button_bounds))
sky 2014/02/06 00:24:10 Because you adjust button_bounds, can this ever be
tdanderson 2014/02/06 01:19:55 The adjustments to |button_bounds| on lines 427 an
442 return;
429 443
430 // TODO: this isn't quite right, really need to intersect the two regions. 444 // Includes padding.
431 path->addRect(RectToSkRect(button_bounds)); 445 path->addRect(RectToSkRect(GetLocalBounds()));
446 } else {
447 // If the hit test request is from mouse, set the hit test mask to be
448 // the region of the button that is visible to the user.
449 path->addRect(RectToSkRect(intersection));
sky 2014/02/06 00:24:10 Why don't you want to do this for both cases?
tdanderson 2014/02/06 01:19:55 I was including the extra padding in the hit test
432 } 450 }
433 } 451 }
434 452
435 virtual const char* GetClassName() const OVERRIDE { 453 virtual const char* GetClassName() const OVERRIDE {
436 return kTabCloseButtonName; 454 return kTabCloseButtonName;
437 } 455 }
438 456
439 private: 457 private:
440 Tab* tab_; 458 Tab* tab_;
441 459
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 const gfx::ImageSkia& image) { 1757 const gfx::ImageSkia& image) {
1740 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1758 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1741 ImageCacheEntry entry; 1759 ImageCacheEntry entry;
1742 entry.resource_id = resource_id; 1760 entry.resource_id = resource_id;
1743 entry.scale_factor = scale_factor; 1761 entry.scale_factor = scale_factor;
1744 entry.image = image; 1762 entry.image = image;
1745 image_cache_->push_front(entry); 1763 image_cache_->push_front(entry);
1746 if (image_cache_->size() > kMaxImageCacheSize) 1764 if (image_cache_->size() > kMaxImageCacheSize)
1747 image_cache_->pop_back(); 1765 image_cache_->pop_back();
1748 } 1766 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_strip.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698