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

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

Issue 381323002: [rough WIP] Make View::GetEventHandlerForRect() non-virtual (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 explicit TabCloseButton(Tab* tab) 238 explicit TabCloseButton(Tab* tab)
239 : views::ImageButton(tab), 239 : views::ImageButton(tab),
240 tab_(tab) { 240 tab_(tab) {
241 SetEventTargeter( 241 SetEventTargeter(
242 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); 242 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
243 } 243 }
244 244
245 virtual ~TabCloseButton() {} 245 virtual ~TabCloseButton() {}
246 246
247 // views::View: 247 // views::View:
248 virtual View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE {
249 if (!views::UsePointBasedTargeting(rect))
250 return View::GetEventHandlerForRect(rect);
251
252 // Ignore the padding set on the button.
253 gfx::Rect contents_bounds = GetContentsBounds();
254 contents_bounds.set_x(GetMirroredXForRect(contents_bounds));
255
256 // Include the padding in hit-test for touch events.
257 if (aura::Env::GetInstance()->is_touch_down())
258 contents_bounds = GetLocalBounds();
259
260 return contents_bounds.Intersects(rect) ? this : parent();
261 }
262
263 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE { 248 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE {
264 // Tab close button has no children, so tooltip handler should be the same 249 // Tab close button has no children, so tooltip handler should be the same
265 // as the event handler. 250 // as the event handler.
266 // In addition, a hit test has to be performed for the point (as 251 // In addition, a hit test has to be performed for the point (as
267 // GetTooltipHandlerForPoint() is responsible for it). 252 // GetTooltipHandlerForPoint() is responsible for it).
268 if (!HitTestPoint(point)) 253 if (!HitTestPoint(point))
269 return NULL; 254 return NULL;
270 return GetEventHandlerForPoint(point); 255 return GetEventHandlerForPoint(point);
271 } 256 }
272 257
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 int top_overflow = tab_bounds.y() - button_bounds.y(); 308 int top_overflow = tab_bounds.y() - button_bounds.y();
324 int bottom_overflow = button_bounds.bottom() - tab_bounds.bottom(); 309 int bottom_overflow = button_bounds.bottom() - tab_bounds.bottom();
325 if (top_overflow > 0) 310 if (top_overflow > 0)
326 button_bounds.set_y(tab_bounds.y()); 311 button_bounds.set_y(tab_bounds.y());
327 else if (bottom_overflow > 0) 312 else if (bottom_overflow > 0)
328 button_bounds.set_height(button_bounds.height() - bottom_overflow); 313 button_bounds.set_height(button_bounds.height() - bottom_overflow);
329 314
330 return button_bounds; 315 return button_bounds;
331 } 316 }
332 317
318 // views::ViewTargeterDelegate:
319 virtual View* TargetForRect(View* root,
320 const gfx::Rect& rect) OVERRIDE {
321 CHECK_EQ(root, this);
322
323 if (!views::UsePointBasedTargeting(rect))
324 return ViewTargeterDelegate::TargetForRect(root, rect);
325
326 // Ignore the padding set on the button.
327 gfx::Rect contents_bounds = GetContentsBounds();
328 contents_bounds.set_x(GetMirroredXForRect(contents_bounds));
329
330 // Include the padding in hit-test for touch events.
331 if (aura::Env::GetInstance()->is_touch_down())
332 contents_bounds = GetLocalBounds();
333
334 return contents_bounds.Intersects(rect) ? this : parent();
335 }
336
333 // views:MaskedTargeterDelegate: 337 // views:MaskedTargeterDelegate:
334 virtual bool GetHitTestMask(gfx::Path* mask) const OVERRIDE { 338 virtual bool GetHitTestMask(gfx::Path* mask) const OVERRIDE {
335 DCHECK(mask); 339 DCHECK(mask);
336 mask->reset(); 340 mask->reset();
337 341
338 // The parent tab may be partially occluded by another tab if we are 342 // The parent tab may be partially occluded by another tab if we are
339 // in stacked tab mode, which means that the tab close button may also 343 // in stacked tab mode, which means that the tab close button may also
340 // be partially occluded. Define the hit test mask of the tab close 344 // be partially occluded. Define the hit test mask of the tab close
341 // button to be the intersection of the parent tab's visible bounds 345 // button to be the intersection of the parent tab's visible bounds
342 // and the bounds of the tab close button. 346 // and the bounds of the tab close button.
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 const gfx::ImageSkia& image) { 1662 const gfx::ImageSkia& image) {
1659 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1663 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1660 ImageCacheEntry entry; 1664 ImageCacheEntry entry;
1661 entry.resource_id = resource_id; 1665 entry.resource_id = resource_id;
1662 entry.scale_factor = scale_factor; 1666 entry.scale_factor = scale_factor;
1663 entry.image = image; 1667 entry.image = image;
1664 image_cache_->push_front(entry); 1668 image_cache_->push_front(entry);
1665 if (image_cache_->size() > kMaxImageCacheSize) 1669 if (image_cache_->size() > kMaxImageCacheSize)
1666 image_cache_->pop_back(); 1670 image_cache_->pop_back();
1667 } 1671 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698