 Chromium Code Reviews
 Chromium Code Reviews Issue 10938009:
  Views fuzzing for Aura and Windows  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@master
    
  
    Issue 10938009:
  Views fuzzing for Aura and Windows  (Closed) 
  Base URL: http://git.chromium.org/chromium/src.git@master| OLD | NEW | 
|---|---|
| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 virtual void AnimationCanceled(const ui::Animation* animation) { | 260 virtual void AnimationCanceled(const ui::Animation* animation) { | 
| 261 tab_->set_dragging(false); | 261 tab_->set_dragging(false); | 
| 262 } | 262 } | 
| 263 | 263 | 
| 264 private: | 264 private: | 
| 265 BaseTab* tab_; | 265 BaseTab* tab_; | 
| 266 | 266 | 
| 267 DISALLOW_COPY_AND_ASSIGN(ResetDraggingStateDelegate); | 267 DISALLOW_COPY_AND_ASSIGN(ResetDraggingStateDelegate); | 
| 268 }; | 268 }; | 
| 269 | 269 | 
| 270 // If |dest| contains the point |point_in_source| the event handler from |dest| | 270 // If |dest| contains the rect |rect_in_source| the event handler from |dest| | 
| 271 // is returned. Otherwise NULL is returned. | 271 // is returned. Otherwise NULL is returned. | 
| 272 views::View* ConvertPointToViewAndGetEventHandler( | 272 views::View* ConvertRectToViewAndGetEventHandler( | 
| 273 views::View* source, | 273 views::View* source, | 
| 274 views::View* dest, | 274 views::View* dest, | 
| 275 const gfx::Point& point_in_source) { | 275 const gfx::Rect& rect_in_source, | 
| 276 gfx::Point dest_point(point_in_source); | 276 views::View::EventType type) { | 
| 277 views::View::ConvertPointToTarget(source, dest, &dest_point); | 277 gfx::Rect dest_rect(rect_in_source); | 
| 278 return dest->HitTestPoint(dest_point) ? | 278 views::View::ConvertRectToTarget(source, dest, &dest_rect); | 
| 279 dest->GetEventHandlerForPoint(dest_point) : NULL; | 279 return dest->HitTestRect(dest_rect) ? | 
| 280 dest->GetEventHandler(dest_rect, type) : NULL; | |
| 280 } | 281 } | 
| 281 | 282 | 
| 282 } // namespace | 283 } // namespace | 
| 283 | 284 | 
| 284 /////////////////////////////////////////////////////////////////////////////// | 285 /////////////////////////////////////////////////////////////////////////////// | 
| 285 // NewTabButton | 286 // NewTabButton | 
| 286 // | 287 // | 
| 287 // A subclass of button that hit-tests to the shape of the new tab button and | 288 // A subclass of button that hit-tests to the shape of the new tab button and | 
| 288 // does custom drawing. | 289 // does custom drawing. | 
| 289 | 290 | 
| 290 class NewTabButton : public views::ImageButton { | 291 class NewTabButton : public views::ImageButton { | 
| 291 public: | 292 public: | 
| 292 NewTabButton(TabStrip* tab_strip, views::ButtonListener* listener); | 293 NewTabButton(TabStrip* tab_strip, views::ButtonListener* listener); | 
| 293 virtual ~NewTabButton(); | 294 virtual ~NewTabButton(); | 
| 294 | 295 | 
| 295 // Set the background offset used to match the background image to the frame | 296 // Set the background offset used to match the background image to the frame | 
| 296 // image. | 297 // image. | 
| 297 void set_background_offset(const gfx::Point& offset) { | 298 void set_background_offset(const gfx::Point& offset) { | 
| 298 background_offset_ = offset; | 299 background_offset_ = offset; | 
| 299 } | 300 } | 
| 300 | 301 | 
| 302 View* GetEventHandler(const gfx::Rect& rect, EventType type) OVERRIDE { | |
| 303 return View::GetEventHandler(rect, type); | |
| 304 } | |
| 305 | |
| 301 protected: | 306 protected: | 
| 302 // Overridden from views::View: | 307 // Overridden from views::View: | 
| 303 virtual bool HasHitTestMask() const OVERRIDE; | 308 virtual bool HasHitTestMask() const OVERRIDE; | 
| 304 virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; | 309 virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; | 
| 305 #if defined(OS_WIN) && !defined(USE_AURA) | 310 #if defined(OS_WIN) && !defined(USE_AURA) | 
| 306 void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 311 void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 
| 307 #endif | 312 #endif | 
| 308 virtual ui::EventResult OnGestureEvent( | 313 virtual ui::EventResult OnGestureEvent( | 
| 309 const ui::GestureEvent& event) OVERRIDE; | 314 const ui::GestureEvent& event) OVERRIDE; | 
| 310 void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 315 void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 | 1338 | 
| 1334 controller()->PerformDrop(drop_before, drop_index, url); | 1339 controller()->PerformDrop(drop_before, drop_index, url); | 
| 1335 | 1340 | 
| 1336 return GetDropEffect(event); | 1341 return GetDropEffect(event); | 
| 1337 } | 1342 } | 
| 1338 | 1343 | 
| 1339 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { | 1344 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { | 
| 1340 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 1345 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 
| 1341 } | 1346 } | 
| 1342 | 1347 | 
| 1343 views::View* TabStrip::GetEventHandlerForPoint(const gfx::Point& point) { | 1348 double CoverageProportion(const gfx::Rect& rect_one, | 
| 
girard
2012/09/18 16:58:52
Move this into the anonymous namespace at the top
 | |
| 1349 const gfx::Rect& rect_two) { | |
| 1350 gfx::Rect intersection = rect_one.Intersect(rect_two); | |
| 1351 double rect_one_area = rect_one.size().GetArea(); | |
| 1352 double rect_two_area = rect_two.size().GetArea(); | |
| 1353 double intersection_area = intersection.size().GetArea(); | |
| 1354 if ((rect_one_area <= 0) || (rect_two_area <= 0)) | |
| 1355 return 0.0; | |
| 1356 if (rect_one_area > rect_two_area) | |
| 1357 return intersection_area / rect_two_area; | |
| 1358 else | |
| 1359 return intersection_area / rect_one_area; | |
| 1360 } | |
| 1361 | |
| 1362 views::View* TabStrip::GetEventHandler(const gfx::Rect& rect, | |
| 1363 EventType type) { | |
| 1364 #if defined(OS_WIN) | |
| 1365 if (ui::IsMouseEventFromTouch(WM_MOUSEMOVE) && (type == MOUSE)) { | |
| 1366 // This MOUSE event was actually generated from a touch. | |
| 1367 // Views doesn't currently enable Windows OS touch. | |
| 1368 int touch_size = 24; | |
| 
tdanderson
2012/09/18 19:19:02
I'm not sure where this 24 comes from. Can you ple
 | |
| 1369 return GetEventHandler(gfx::Rect(rect.x()-touch_size, rect.y()-touch_size, | |
| 1370 touch_size*2, touch_size*2), TOUCH); | |
| 1371 } | |
| 1372 #endif | |
| 1373 | |
| 1374 View* closest_view = NULL; | |
| 1375 View* closest_untouched_view = NULL; | |
| 1376 double max_proportion = 0; | |
| 1377 int closest_distance = INT_MAX; | |
| 
tdanderson
2012/09/18 19:19:02
Are you planning on using these in the same way as
 | |
| 1378 | |
| 1344 if (!touch_layout_.get()) { | 1379 if (!touch_layout_.get()) { | 
| 1345 // Return any view that isn't a Tab or this TabStrip immediately. We don't | 1380 // Return any view that isn't a Tab or this TabStrip immediately. We don't | 
| 1346 // want to interfere. | 1381 // want to interfere. | 
| 1347 views::View* v = View::GetEventHandlerForPoint(point); | 1382 views::View* v = View::GetEventHandler(rect, type); | 
| 1348 if (v && v != this && v->GetClassName() != Tab::kViewClassName) | 1383 if (v && v != this && v->GetClassName() != Tab::kViewClassName) | 
| 1349 return v; | 1384 return v; | 
| 1350 | 1385 | 
| 1351 // The display order doesn't necessarily match the child list order, so we | 1386 // The display order doesn't necessarily match the child list order, so we | 
| 1352 // walk the display list hit-testing Tabs. Since the active tab always | 1387 // walk the display list hit-testing Tabs. Since the active tab always | 
| 1353 // renders on top of adjacent tabs, it needs to be hit-tested before any | 1388 // renders on top of adjacent tabs, it needs to be hit-tested before any | 
| 1354 // left-adjacent Tab, so we look ahead for it as we walk. | 1389 // left-adjacent Tab, so we look ahead for it as we walk. | 
| 1355 for (int i = 0; i < tab_count(); ++i) { | 1390 for (int i = 0; i < tab_count(); ++i) { | 
| 1356 Tab* next_tab = i < (tab_count() - 1) ? tab_at(i + 1) : NULL; | 1391 Tab* next_tab = i < (tab_count() - 1) ? tab_at(i + 1) : NULL; | 
| 1357 if (next_tab && next_tab->IsActive() && IsPointInTab(next_tab, point)) | 1392 if (next_tab && next_tab->IsActive() && IsRectInTab(next_tab, rect)) | 
| 1358 return next_tab; | 1393 return next_tab; | 
| 1359 if (IsPointInTab(tab_at(i), point)) | 1394 if (IsRectInTab(tab_at(i), rect)) | 
| 1360 return tab_at(i); | 1395 return tab_at(i); | 
| 1361 } | 1396 } | 
| 1362 } else { | 1397 } else { | 
| 1398 // Test for new tab button.... | |
| 1363 if (newtab_button_->visible()) { | 1399 if (newtab_button_->visible()) { | 
| 1364 views::View* view = | 1400 views::View* view = | 
| 1365 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 1401 ConvertRectToViewAndGetEventHandler( | 
| 1402 this, newtab_button_, rect, type); | |
| 1366 if (view) | 1403 if (view) | 
| 
girard
2012/09/18 16:58:52
This should only return if MOUSE.  Otherwise conti
 | |
| 1367 return view; | 1404 return view; | 
| 1368 } | 1405 } | 
| 1369 Tab* tab = FindTabForEvent(point); | 1406 // Otherwise, check for other tabs.... | 
| 1407 Tab* tab = FindTabForEvent(rect); | |
| 
girard
2012/09/18 16:58:52
This logic should be expanded here, so we can cons
 | |
| 1370 if (tab) | 1408 if (tab) | 
| 1371 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 1409 return ConvertRectToViewAndGetEventHandler(this, tab, rect, type); | 
| 
girard
2012/09/18 16:58:52
Ditto.
 | |
| 1372 } | 1410 } | 
| 1373 return this; | 1411 return this; | 
| 1374 } | 1412 } | 
| 1375 | 1413 | 
| 1376 int TabStrip::GetMiniTabCount() const { | 1414 int TabStrip::GetMiniTabCount() const { | 
| 1377 int mini_count = 0; | 1415 int mini_count = 0; | 
| 1378 while (mini_count < tab_count() && tab_at(mini_count)->data().mini) | 1416 while (mini_count < tab_count() && tab_at(mini_count)->data().mini) | 
| 1379 mini_count++; | 1417 mini_count++; | 
| 1380 return mini_count; | 1418 return mini_count; | 
| 1381 } | 1419 } | 
| (...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2345 true); | 2383 true); | 
| 2346 } | 2384 } | 
| 2347 | 2385 | 
| 2348 bool TabStrip::IsPointInTab(Tab* tab, | 2386 bool TabStrip::IsPointInTab(Tab* tab, | 
| 2349 const gfx::Point& point_in_tabstrip_coords) { | 2387 const gfx::Point& point_in_tabstrip_coords) { | 
| 2350 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 2388 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 
| 2351 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); | 2389 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); | 
| 2352 return tab->HitTestPoint(point_in_tab_coords); | 2390 return tab->HitTestPoint(point_in_tab_coords); | 
| 2353 } | 2391 } | 
| 2354 | 2392 | 
| 2393 bool TabStrip::IsRectInTab(Tab* tab, | |
| 2394 const gfx::Rect& rect_in_tabstrip_coords) { | |
| 2395 gfx::Rect rect_in_tab_coords(rect_in_tabstrip_coords); | |
| 2396 View::ConvertRectToTarget(this, tab, &rect_in_tab_coords); | |
| 2397 return tab->HitTestRect(rect_in_tab_coords); | |
| 2398 } | |
| 2399 | |
| 2355 int TabStrip::GetStartXForNormalTabs() const { | 2400 int TabStrip::GetStartXForNormalTabs() const { | 
| 2356 int mini_tab_count = GetMiniTabCount(); | 2401 int mini_tab_count = GetMiniTabCount(); | 
| 2357 if (mini_tab_count == 0) | 2402 if (mini_tab_count == 0) | 
| 2358 return 0; | 2403 return 0; | 
| 2359 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + | 2404 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + | 
| 2360 kMiniToNonMiniGap; | 2405 kMiniToNonMiniGap; | 
| 2361 } | 2406 } | 
| 2362 | 2407 | 
| 2408 Tab* TabStrip::FindTabForEvent(const gfx::Rect& rect) { | |
| 2409 DCHECK(touch_layout_.get()); | |
| 2410 int active_tab_index = touch_layout_->active_index(); | |
| 2411 Tab* tab = NULL; | |
| 2412 if (active_tab_index != -1) { | |
| 2413 tab = FindTabForEventFrom(rect, active_tab_index, -1); | |
| 2414 if (!tab) | |
| 2415 tab = FindTabForEventFrom(rect, active_tab_index + 1, 1); | |
| 2416 } else if (tab_count()) { | |
| 2417 tab = FindTabForEventFrom(rect, 0, 1); | |
| 2418 } | |
| 2419 return tab; | |
| 2420 } | |
| 2421 | |
| 2363 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { | 2422 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { | 
| 2364 DCHECK(touch_layout_.get()); | 2423 DCHECK(touch_layout_.get()); | 
| 2365 int active_tab_index = touch_layout_->active_index(); | 2424 int active_tab_index = touch_layout_->active_index(); | 
| 2366 Tab* tab = NULL; | 2425 Tab* tab = NULL; | 
| 2367 if (active_tab_index != -1) { | 2426 if (active_tab_index != -1) { | 
| 2368 tab = FindTabForEventFrom(point, active_tab_index, -1); | 2427 tab = FindTabForEventFrom(point, active_tab_index, -1); | 
| 2369 if (!tab) | 2428 if (!tab) | 
| 2370 tab = FindTabForEventFrom(point, active_tab_index + 1, 1); | 2429 tab = FindTabForEventFrom(point, active_tab_index + 1, 1); | 
| 2371 } else if (tab_count()) { | 2430 } else if (tab_count()) { | 
| 2372 tab = FindTabForEventFrom(point, 0, 1); | 2431 tab = FindTabForEventFrom(point, 0, 1); | 
| 2373 } | 2432 } | 
| 2374 return tab; | 2433 return tab; | 
| 2375 } | 2434 } | 
| 2376 | 2435 | 
| 2436 Tab* TabStrip::FindTabForEventFrom(const gfx::Rect& rect, | |
| 2437 int start, | |
| 2438 int delta) { | |
| 2439 // |start| equals tab_count() when there are only pinned tabs. | |
| 2440 if (start == tab_count()) | |
| 2441 start += delta; | |
| 2442 for (int i = start; i >= 0 && i < tab_count(); i += delta) { | |
| 2443 if (IsRectInTab(tab_at(i), rect)) | |
| 2444 return tab_at(i); | |
| 2445 } | |
| 2446 return NULL; | |
| 2447 } | |
| 2448 | |
| 2377 Tab* TabStrip::FindTabForEventFrom(const gfx::Point& point, | 2449 Tab* TabStrip::FindTabForEventFrom(const gfx::Point& point, | 
| 2378 int start, | 2450 int start, | 
| 2379 int delta) { | 2451 int delta) { | 
| 2380 // |start| equals tab_count() when there are only pinned tabs. | 2452 // |start| equals tab_count() when there are only pinned tabs. | 
| 2381 if (start == tab_count()) | 2453 if (start == tab_count()) | 
| 2382 start += delta; | 2454 start += delta; | 
| 2383 for (int i = start; i >= 0 && i < tab_count(); i += delta) { | 2455 for (int i = start; i >= 0 && i < tab_count(); i += delta) { | 
| 2384 if (IsPointInTab(tab_at(i), point)) | 2456 if (IsPointInTab(tab_at(i), point)) | 
| 2385 return tab_at(i); | 2457 return tab_at(i); | 
| 2386 } | 2458 } | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2458 if (!adjust_layout_) | 2530 if (!adjust_layout_) | 
| 2459 return false; | 2531 return false; | 
| 2460 | 2532 | 
| 2461 #if !defined(OS_CHROMEOS) | 2533 #if !defined(OS_CHROMEOS) | 
| 2462 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2534 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 
| 2463 return false; | 2535 return false; | 
| 2464 #endif | 2536 #endif | 
| 2465 | 2537 | 
| 2466 return true; | 2538 return true; | 
| 2467 } | 2539 } | 
| OLD | NEW |