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

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

Issue 32463003: Modify hit test masks for tabs and tab close buttons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch for landing Created 7 years, 1 month 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 21 matching lines...) Expand all
32 #include "ui/base/theme_provider.h" 32 #include "ui/base/theme_provider.h"
33 #include "ui/gfx/animation/animation_container.h" 33 #include "ui/gfx/animation/animation_container.h"
34 #include "ui/gfx/animation/multi_animation.h" 34 #include "ui/gfx/animation/multi_animation.h"
35 #include "ui/gfx/animation/throb_animation.h" 35 #include "ui/gfx/animation/throb_animation.h"
36 #include "ui/gfx/canvas.h" 36 #include "ui/gfx/canvas.h"
37 #include "ui/gfx/color_analysis.h" 37 #include "ui/gfx/color_analysis.h"
38 #include "ui/gfx/favicon_size.h" 38 #include "ui/gfx/favicon_size.h"
39 #include "ui/gfx/font.h" 39 #include "ui/gfx/font.h"
40 #include "ui/gfx/image/image_skia_operations.h" 40 #include "ui/gfx/image/image_skia_operations.h"
41 #include "ui/gfx/path.h" 41 #include "ui/gfx/path.h"
42 #include "ui/gfx/rect_conversions.h"
43 #include "ui/gfx/skia_util.h"
42 #include "ui/gfx/text_elider.h" 44 #include "ui/gfx/text_elider.h"
43 #include "ui/views/controls/button/image_button.h" 45 #include "ui/views/controls/button/image_button.h"
44 #include "ui/views/widget/tooltip_manager.h" 46 #include "ui/views/widget/tooltip_manager.h"
45 #include "ui/views/widget/widget.h" 47 #include "ui/views/widget/widget.h"
46 #include "ui/views/window/non_client_view.h" 48 #include "ui/views/window/non_client_view.h"
47 49
48 #if defined(OS_WIN) 50 #if defined(OS_WIN)
49 #include "win8/util/win8_util.h" 51 #include "win8/util/win8_util.h"
50 #endif 52 #endif
51 53
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 const SkColor kImmersiveActiveTabColor = SkColorSetRGB(235, 235, 235); 237 const SkColor kImmersiveActiveTabColor = SkColorSetRGB(235, 235, 235);
236 const SkColor kImmersiveInactiveTabColor = SkColorSetRGB(190, 190, 190); 238 const SkColor kImmersiveInactiveTabColor = SkColorSetRGB(190, 190, 190);
237 239
238 // The minimum opacity (out of 1) when a tab (either active or inactive) is 240 // The minimum opacity (out of 1) when a tab (either active or inactive) is
239 // throbbing in the immersive mode light strip. 241 // throbbing in the immersive mode light strip.
240 const double kImmersiveTabMinThrobOpacity = 0.66; 242 const double kImmersiveTabMinThrobOpacity = 0.66;
241 243
242 // Number of steps in the immersive mode loading animation. 244 // Number of steps in the immersive mode loading animation.
243 const int kImmersiveLoadingStepCount = 32; 245 const int kImmersiveLoadingStepCount = 32;
244 246
247 const char kTabCloseButtonName[] = "TabCloseButton";
248
245 void DrawIconAtLocation(gfx::Canvas* canvas, 249 void DrawIconAtLocation(gfx::Canvas* canvas,
246 const gfx::ImageSkia& image, 250 const gfx::ImageSkia& image,
247 int image_offset, 251 int image_offset,
248 int dst_x, 252 int dst_x,
249 int dst_y, 253 int dst_y,
250 int icon_width, 254 int icon_width,
251 int icon_height, 255 int icon_height,
252 bool filter, 256 bool filter,
253 const SkPaint& paint) { 257 const SkPaint& paint) {
254 // NOTE: the clipping is a work around for 69528, it shouldn't be necessary. 258 // NOTE: the clipping is a work around for 69528, it shouldn't be necessary.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 CustomButton::OnMouseReleased(event); 405 CustomButton::OnMouseReleased(event);
402 } 406 }
403 407
404 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 408 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
405 // Consume all gesture events here so that the parent (Tab) does not 409 // Consume all gesture events here so that the parent (Tab) does not
406 // start consuming gestures. 410 // start consuming gestures.
407 ImageButton::OnGestureEvent(event); 411 ImageButton::OnGestureEvent(event);
408 event->SetHandled(); 412 event->SetHandled();
409 } 413 }
410 414
415 virtual bool HasHitTestMask() const OVERRIDE {
416 return true;
417 }
418
419 virtual void GetHitTestMask(HitTestSource source,
420 gfx::Path* path) const OVERRIDE {
421 // Use the button's contents bounds (which does not include padding)
422 // and the hit test mask of our parent |tab_| to determine if the
423 // button is hidden behind another tab.
424 gfx::Path tab_mask;
425 tab_->GetHitTestMask(source, &tab_mask);
426
427 gfx::Rect button_bounds(GetContentsBounds());
428 gfx::RectF tab_bounds_f(gfx::SkRectToRectF(tab_mask.getBounds()));
429 views::View::ConvertRectToTarget(tab_, this, &tab_bounds_f);
430 gfx::Rect tab_bounds = gfx::ToEnclosingRect(tab_bounds_f);
431
432 // If the button is hidden behind another tab, the hit test mask is empty.
433 // Otherwise set the hit test mask to be the contents bounds.
434 path->reset();
435 if (tab_bounds.Contains(button_bounds)) {
436 // Include the padding in the hit test mask for touch events.
437 if (source == HIT_TEST_SOURCE_TOUCH)
438 button_bounds = GetLocalBounds();
439
440 path->addRect(RectToSkRect(button_bounds));
441 }
442 }
443
444 virtual const char* GetClassName() const OVERRIDE {
445 return kTabCloseButtonName;
446 }
447
411 private: 448 private:
412 Tab* tab_; 449 Tab* tab_;
413 450
414 DISALLOW_COPY_AND_ASSIGN(TabCloseButton); 451 DISALLOW_COPY_AND_ASSIGN(TabCloseButton);
415 }; 452 };
416 453
417 //////////////////////////////////////////////////////////////////////////////// 454 ////////////////////////////////////////////////////////////////////////////////
418 // ImageCacheEntry 455 // ImageCacheEntry
419 456
420 Tab::ImageCacheEntry::ImageCacheEntry() 457 Tab::ImageCacheEntry::ImageCacheEntry()
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 902 }
866 903
867 const char* Tab::GetClassName() const { 904 const char* Tab::GetClassName() const {
868 return kViewClassName; 905 return kViewClassName;
869 } 906 }
870 907
871 bool Tab::HasHitTestMask() const { 908 bool Tab::HasHitTestMask() const {
872 return true; 909 return true;
873 } 910 }
874 911
875 void Tab::GetHitTestMask(gfx::Path* path) const { 912 void Tab::GetHitTestMask(HitTestSource source, gfx::Path* path) const {
876 // When the window is maximized we don't want to shave off the edges or top 913 // When the window is maximized we don't want to shave off the edges or top
877 // shadow of the tab, such that the user can click anywhere along the top 914 // shadow of the tab, such that the user can click anywhere along the top
878 // edge of the screen to select a tab. Ditto for immersive fullscreen. 915 // edge of the screen to select a tab. Ditto for immersive fullscreen.
879 const views::Widget* widget = GetWidget(); 916 const views::Widget* widget = GetWidget();
880 bool include_top_shadow = 917 bool include_top_shadow =
881 widget && (widget->IsMaximized() || widget->IsFullscreen()); 918 widget && (widget->IsMaximized() || widget->IsFullscreen());
882 TabResources::GetHitTestMask(width(), height(), include_top_shadow, path); 919 TabResources::GetHitTestMask(width(), height(), include_top_shadow, path);
920
921 // It is possible for a portion of the tab to be occluded if tabs are
922 // stacked, so modify the hit test mask to only include the visible
923 // region of the tab.
924 if (controller()) {
925 gfx::Rect clip;
926 controller()->ShouldPaintTab(this, &clip);
927 if (clip.size().GetArea()) {
928 SkRect intersection(path->getBounds());
929 intersection.intersect(RectToSkRect(clip));
930 path->reset();
931 path->addRect(intersection);
932 }
933 }
883 } 934 }
884 935
885 bool Tab::GetTooltipText(const gfx::Point& p, string16* tooltip) const { 936 bool Tab::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
886 // TODO(miu): Rectify inconsistent tooltip behavior. http://crbug.com/310947 937 // TODO(miu): Rectify inconsistent tooltip behavior. http://crbug.com/310947
887 938
888 if (data_.media_state != TAB_MEDIA_STATE_NONE) { 939 if (data_.media_state != TAB_MEDIA_STATE_NONE) {
889 *tooltip = chrome::AssembleTabTooltipText(data_.title, data_.media_state); 940 *tooltip = chrome::AssembleTabTooltipText(data_.title, data_.media_state);
890 return true; 941 return true;
891 } 942 }
892 943
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 const gfx::ImageSkia& image) { 1780 const gfx::ImageSkia& image) {
1730 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1781 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1731 ImageCacheEntry entry; 1782 ImageCacheEntry entry;
1732 entry.resource_id = resource_id; 1783 entry.resource_id = resource_id;
1733 entry.scale_factor = scale_factor; 1784 entry.scale_factor = scale_factor;
1734 entry.image = image; 1785 entry.image = image;
1735 image_cache_->push_front(entry); 1786 image_cache_->push_front(entry);
1736 if (image_cache_->size() > kMaxImageCacheSize) 1787 if (image_cache_->size() > kMaxImageCacheSize)
1737 image_cache_->pop_back(); 1788 image_cache_->pop_back();
1738 } 1789 }
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