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

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

Issue 22891016: Add support for rect-based event targeting in views (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed Created 7 years, 3 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 // Number of steps in the immersive mode loading animation. 245 // Number of steps in the immersive mode loading animation.
246 const int kImmersiveLoadingStepCount = 32; 246 const int kImmersiveLoadingStepCount = 32;
247 247
248 // Scale to resize the current favicon by when projecting. 248 // Scale to resize the current favicon by when projecting.
249 const double kProjectingFaviconResizeScale = 0.75; 249 const double kProjectingFaviconResizeScale = 0.75;
250 250
251 // Scale to resize the projection sheet glow by. 251 // Scale to resize the projection sheet glow by.
252 const double kProjectingGlowResizeScale = 2.0; 252 const double kProjectingGlowResizeScale = 2.0;
253 253
254 const char kTabCloseButtonName[] = "TabCloseButton";
255
254 void DrawIconAtLocation(gfx::Canvas* canvas, 256 void DrawIconAtLocation(gfx::Canvas* canvas,
255 const gfx::ImageSkia& image, 257 const gfx::ImageSkia& image,
256 int image_offset, 258 int image_offset,
257 int dst_x, 259 int dst_x,
258 int dst_y, 260 int dst_y,
259 int icon_width, 261 int icon_width,
260 int icon_height, 262 int icon_height,
261 bool filter, 263 bool filter,
262 const SkPaint& paint) { 264 const SkPaint& paint) {
263 // NOTE: the clipping is a work around for 69528, it shouldn't be necessary. 265 // NOTE: the clipping is a work around for 69528, it shouldn't be necessary.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // TabCloseButton 355 // TabCloseButton
354 // 356 //
355 // This is a Button subclass that causes middle clicks to be forwarded to the 357 // This is a Button subclass that causes middle clicks to be forwarded to the
356 // parent View by explicitly not handling them in OnMousePressed. 358 // parent View by explicitly not handling them in OnMousePressed.
357 class Tab::TabCloseButton : public views::ImageButton { 359 class Tab::TabCloseButton : public views::ImageButton {
358 public: 360 public:
359 explicit TabCloseButton(Tab* tab) : views::ImageButton(tab), tab_(tab) {} 361 explicit TabCloseButton(Tab* tab) : views::ImageButton(tab), tab_(tab) {}
360 virtual ~TabCloseButton() {} 362 virtual ~TabCloseButton() {}
361 363
362 // Overridden from views::View. 364 // Overridden from views::View.
363 virtual View* GetEventHandlerForPoint(const gfx::Point& point) OVERRIDE { 365 virtual View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE {
366 if (!View::UsePointBasedTargeting(rect))
367 return View::GetEventHandlerForRect(rect);
368
364 // Ignore the padding set on the button. 369 // Ignore the padding set on the button.
365 gfx::Rect rect = GetContentsBounds(); 370 gfx::Rect contents_bounds = GetContentsBounds();
366 rect.set_x(GetMirroredXForRect(rect)); 371 contents_bounds.set_x(GetMirroredXForRect(contents_bounds));
367 372
368 #if defined(USE_ASH) 373 #if defined(USE_ASH)
369 // Include the padding in hit-test for touch events. 374 // Include the padding in hit-test for touch events.
370 if (aura::Env::GetInstance()->is_touch_down()) 375 if (aura::Env::GetInstance()->is_touch_down())
371 rect = GetLocalBounds(); 376 contents_bounds = GetLocalBounds();
372 #elif defined(OS_WIN) 377 #elif defined(OS_WIN)
373 // TODO(sky): Use local-bounds if a touch-point is active. 378 // TODO(sky): Use local-bounds if a touch-point is active.
374 // http://crbug.com/145258 379 // http://crbug.com/145258
375 #endif 380 #endif
376 381
377 return rect.Contains(point) ? this : parent(); 382 return contents_bounds.Intersects(rect) ? this : parent();
378 } 383 }
379 384
380 // Overridden from views::View. 385 // Overridden from views::View.
381 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE { 386 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE {
382 // Tab close button has no children, so tooltip handler should be the same 387 // Tab close button has no children, so tooltip handler should be the same
383 // as the event handler. 388 // as the event handler.
384 // In addition, a hit test has to be performed for the point (as 389 // In addition, a hit test has to be performed for the point (as
385 // GetTooltipHandlerForPoint() is responsible for it). 390 // GetTooltipHandlerForPoint() is responsible for it).
386 if (!HitTestPoint(point)) 391 if (!HitTestPoint(point))
387 return NULL; 392 return NULL;
(...skipping 22 matching lines...) Expand all
410 CustomButton::OnMouseReleased(event); 415 CustomButton::OnMouseReleased(event);
411 } 416 }
412 417
413 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 418 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
414 // Consume all gesture events here so that the parent (Tab) does not 419 // Consume all gesture events here so that the parent (Tab) does not
415 // start consuming gestures. 420 // start consuming gestures.
416 ImageButton::OnGestureEvent(event); 421 ImageButton::OnGestureEvent(event);
417 event->SetHandled(); 422 event->SetHandled();
418 } 423 }
419 424
425 virtual const char* GetClassName() const OVERRIDE {
426 return kTabCloseButtonName;
427 }
428
420 private: 429 private:
421 Tab* tab_; 430 Tab* tab_;
422 431
423 DISALLOW_COPY_AND_ASSIGN(TabCloseButton); 432 DISALLOW_COPY_AND_ASSIGN(TabCloseButton);
424 }; 433 };
425 434
426 //////////////////////////////////////////////////////////////////////////////// 435 ////////////////////////////////////////////////////////////////////////////////
427 // ImageCacheEntry 436 // ImageCacheEntry
428 437
429 Tab::ImageCacheEntry::ImageCacheEntry() 438 Tab::ImageCacheEntry::ImageCacheEntry()
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 const gfx::ImageSkia& image) { 1843 const gfx::ImageSkia& image) {
1835 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1844 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1836 ImageCacheEntry entry; 1845 ImageCacheEntry entry;
1837 entry.resource_id = resource_id; 1846 entry.resource_id = resource_id;
1838 entry.scale_factor = scale_factor; 1847 entry.scale_factor = scale_factor;
1839 entry.image = image; 1848 entry.image = image;
1840 image_cache_->push_front(entry); 1849 image_cache_->push_front(entry);
1841 if (image_cache_->size() > kMaxImageCacheSize) 1850 if (image_cache_->size() > kMaxImageCacheSize)
1842 image_cache_->pop_back(); 1851 image_cache_->pop_back();
1843 } 1852 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698