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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip.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, moved fuzzing utility functions to new file Created 7 years, 2 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_strip.h" 5 #include "chrome/browser/ui/views/tabs/tab_strip.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windowsx.h> 8 #include <windowsx.h>
9 #endif 9 #endif
10 10
(...skipping 29 matching lines...) Expand all
40 #include "ui/gfx/animation/throb_animation.h" 40 #include "ui/gfx/animation/throb_animation.h"
41 #include "ui/gfx/canvas.h" 41 #include "ui/gfx/canvas.h"
42 #include "ui/gfx/display.h" 42 #include "ui/gfx/display.h"
43 #include "ui/gfx/image/image_skia.h" 43 #include "ui/gfx/image/image_skia.h"
44 #include "ui/gfx/image/image_skia_operations.h" 44 #include "ui/gfx/image/image_skia_operations.h"
45 #include "ui/gfx/path.h" 45 #include "ui/gfx/path.h"
46 #include "ui/gfx/screen.h" 46 #include "ui/gfx/screen.h"
47 #include "ui/gfx/size.h" 47 #include "ui/gfx/size.h"
48 #include "ui/views/controls/image_view.h" 48 #include "ui/views/controls/image_view.h"
49 #include "ui/views/mouse_watcher_view_host.h" 49 #include "ui/views/mouse_watcher_view_host.h"
50 #include "ui/views/rect_based_targeting_utils.h"
50 #include "ui/views/view_model_utils.h" 51 #include "ui/views/view_model_utils.h"
51 #include "ui/views/widget/root_view.h" 52 #include "ui/views/widget/root_view.h"
52 #include "ui/views/widget/widget.h" 53 #include "ui/views/widget/widget.h"
53 #include "ui/views/window/non_client_view.h" 54 #include "ui/views/window/non_client_view.h"
54 55
55 #if defined(OS_WIN) 56 #if defined(OS_WIN)
56 #include "ui/gfx/win/hwnd_util.h" 57 #include "ui/gfx/win/hwnd_util.h"
57 #include "ui/views/widget/monitor_win.h" 58 #include "ui/views/widget/monitor_win.h"
58 #include "win8/util/win8_util.h" 59 #include "win8/util/win8_util.h"
59 #endif 60 #endif
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE { 249 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE {
249 tab_->set_dragging(false); 250 tab_->set_dragging(false);
250 } 251 }
251 252
252 private: 253 private:
253 Tab* tab_; 254 Tab* tab_;
254 255
255 DISALLOW_COPY_AND_ASSIGN(ResetDraggingStateDelegate); 256 DISALLOW_COPY_AND_ASSIGN(ResetDraggingStateDelegate);
256 }; 257 };
257 258
258 // If |dest| contains the point |point_in_source| the event handler from |dest| 259 // If |dest| intersects the rect |rect_in_source| the event handler from |dest|
259 // is returned. Otherwise NULL is returned. 260 // is returned. Otherwise NULL is returned.
260 views::View* ConvertPointToViewAndGetEventHandler( 261 views::View* ConvertRectToViewAndGetEventHandler(
261 views::View* source, 262 views::View* source,
262 views::View* dest, 263 views::View* dest,
263 const gfx::Point& point_in_source) { 264 const gfx::Rect& rect_in_source) {
264 gfx::Point dest_point(point_in_source); 265 gfx::Rect dest_rect(rect_in_source);
265 views::View::ConvertPointToTarget(source, dest, &dest_point); 266 views::View::ConvertRectToTarget(source, dest, &dest_rect);
266 return dest->HitTestPoint(dest_point) ? 267 return dest->HitTestRect(dest_rect) ?
267 dest->GetEventHandlerForPoint(dest_point) : NULL; 268 dest->GetEventHandlerForRect(dest_rect) : NULL;
268 } 269 }
269 270
270 // Gets a tooltip handler for |point_in_source| from |dest|. Note that |dest| 271 // Gets a tooltip handler for |point_in_source| from |dest|. Note that |dest|
271 // should return NULL if it does not contain the point. 272 // should return NULL if it does not contain the point.
272 views::View* ConvertPointToViewAndGetTooltipHandler( 273 views::View* ConvertPointToViewAndGetTooltipHandler(
273 views::View* source, 274 views::View* source,
274 views::View* dest, 275 views::View* dest,
275 const gfx::Point& point_in_source) { 276 const gfx::Point& point_in_source) {
276 gfx::Point dest_point(point_in_source); 277 gfx::Point dest_point(point_in_source);
277 views::View::ConvertPointToTarget(source, dest, &dest_point); 278 views::View::ConvertPointToTarget(source, dest, &dest_point);
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 905
905 bool TabStrip::IsTabStripCloseable() const { 906 bool TabStrip::IsTabStripCloseable() const {
906 return !IsDragSessionActive(); 907 return !IsDragSessionActive();
907 } 908 }
908 909
909 void TabStrip::UpdateLoadingAnimations() { 910 void TabStrip::UpdateLoadingAnimations() {
910 controller_->UpdateLoadingAnimations(); 911 controller_->UpdateLoadingAnimations();
911 } 912 }
912 913
913 bool TabStrip::IsPositionInWindowCaption(const gfx::Point& point) { 914 bool TabStrip::IsPositionInWindowCaption(const gfx::Point& point) {
914 views::View* v = GetEventHandlerForPoint(point); 915 return IsRectInWindowCaption(gfx::Rect(point, gfx::Size(1, 1)));
916 }
917
918 bool TabStrip::IsRectInWindowCaption(const gfx::Rect& rect) {
919 views::View* v = GetEventHandlerForRect(rect);
915 920
916 // If there is no control at this location, claim the hit was in the title 921 // If there is no control at this location, claim the hit was in the title
917 // bar to get a move action. 922 // bar to get a move action.
918 if (v == this) 923 if (v == this)
919 return true; 924 return true;
920 925
921 // Check to see if the point is within the non-button parts of the new tab 926 // Check to see if the rect intersects the non-button parts of the new tab
922 // button. The button has a non-rectangular shape, so if it's not in the 927 // button. The button has a non-rectangular shape, so if it's not in the
923 // visual portions of the button we treat it as a click to the caption. 928 // visual portions of the button we treat it as a click to the caption.
924 gfx::Point point_in_newtab_coords(point); 929 gfx::Rect rect_in_newtab_coords(rect);
925 View::ConvertPointToTarget(this, newtab_button_, &point_in_newtab_coords); 930 View::ConvertRectToTarget(this, newtab_button_, &rect_in_newtab_coords);
926 if (newtab_button_->GetLocalBounds().Contains(point_in_newtab_coords) && 931 if (newtab_button_->GetLocalBounds().Intersects(rect_in_newtab_coords) &&
927 !newtab_button_->HitTestPoint(point_in_newtab_coords)) { 932 !newtab_button_->HitTestRect(rect_in_newtab_coords))
928 return true; 933 return true;
929 }
930 934
931 // All other regions, including the new Tab button, should be considered part 935 // All other regions, including the new Tab button, should be considered part
932 // of the containing Window's client area so that regular events can be 936 // of the containing Window's client area so that regular events can be
933 // processed for them. 937 // processed for them.
934 return false; 938 return false;
935 } 939 }
936 940
937 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { 941 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) {
938 for (int i = 0; i < tab_count(); ++i) 942 for (int i = 0; i < tab_count(); ++i)
939 tab_at(i)->set_background_offset(offset); 943 tab_at(i)->set_background_offset(offset);
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 1419
1416 controller()->PerformDrop(drop_before, drop_index, url); 1420 controller()->PerformDrop(drop_before, drop_index, url);
1417 1421
1418 return GetDropEffect(event); 1422 return GetDropEffect(event);
1419 } 1423 }
1420 1424
1421 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { 1425 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) {
1422 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; 1426 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST;
1423 } 1427 }
1424 1428
1425 views::View* TabStrip::GetEventHandlerForPoint(const gfx::Point& point) { 1429 views::View* TabStrip::GetEventHandlerForRect(const gfx::Rect& rect) {
1430 if (!views::UsePointBasedTargeting(rect))
1431 return View::GetEventHandlerForRect(rect);
1432
1426 if (!touch_layout_.get()) { 1433 if (!touch_layout_.get()) {
1427 // Return any view that isn't a Tab or this TabStrip immediately. We don't 1434 // Return any view that isn't a Tab or this TabStrip immediately. We don't
1428 // want to interfere. 1435 // want to interfere.
1429 views::View* v = View::GetEventHandlerForPoint(point); 1436 views::View* v = View::GetEventHandlerForRect(rect);
1430 if (v && v != this && strcmp(v->GetClassName(), Tab::kViewClassName)) 1437 if (v && v != this && strcmp(v->GetClassName(), Tab::kViewClassName))
1431 return v; 1438 return v;
1432 1439
1433 views::View* tab = FindTabHitByPoint(point); 1440 views::View* tab = FindTabHitByPoint(rect.CenterPoint());
1434 if (tab) 1441 if (tab)
1435 return tab; 1442 return tab;
1436 } else { 1443 } else {
1437 if (newtab_button_->visible()) { 1444 if (newtab_button_->visible()) {
1438 views::View* view = 1445 views::View* view =
1439 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); 1446 ConvertRectToViewAndGetEventHandler(this, newtab_button_, rect);
1440 if (view) 1447 if (view)
1441 return view; 1448 return view;
1442 } 1449 }
1443 Tab* tab = FindTabForEvent(point); 1450 Tab* tab = FindTabForEvent(rect.CenterPoint());
1444 if (tab) 1451 if (tab)
1445 return ConvertPointToViewAndGetEventHandler(this, tab, point); 1452 return ConvertRectToViewAndGetEventHandler(this, tab, rect);
1446 } 1453 }
1447 return this; 1454 return this;
1448 } 1455 }
1449 1456
1450 views::View* TabStrip::GetTooltipHandlerForPoint(const gfx::Point& point) { 1457 views::View* TabStrip::GetTooltipHandlerForPoint(const gfx::Point& point) {
1451 if (!HitTestPoint(point)) 1458 if (!HitTestPoint(point))
1452 return NULL; 1459 return NULL;
1453 1460
1454 if (!touch_layout_.get()) { 1461 if (!touch_layout_.get()) {
1455 // Return any view that isn't a Tab or this TabStrip immediately. We don't 1462 // Return any view that isn't a Tab or this TabStrip immediately. We don't
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
2712 if (!adjust_layout_) 2719 if (!adjust_layout_)
2713 return false; 2720 return false;
2714 2721
2715 #if !defined(OS_CHROMEOS) 2722 #if !defined(OS_CHROMEOS)
2716 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) 2723 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH)
2717 return false; 2724 return false;
2718 #endif 2725 #endif
2719 2726
2720 return true; 2727 return true;
2721 } 2728 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698