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 25 matching lines...) Expand all Loading... |
36 #include "ui/base/layout.h" | 36 #include "ui/base/layout.h" |
37 #include "ui/base/models/list_selection_model.h" | 37 #include "ui/base/models/list_selection_model.h" |
38 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
39 #include "ui/gfx/animation/animation_container.h" | 39 #include "ui/gfx/animation/animation_container.h" |
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/rect_conversions.h" |
46 #include "ui/gfx/screen.h" | 47 #include "ui/gfx/screen.h" |
47 #include "ui/gfx/size.h" | 48 #include "ui/gfx/size.h" |
48 #include "ui/views/controls/image_view.h" | 49 #include "ui/views/controls/image_view.h" |
49 #include "ui/views/mouse_watcher_view_host.h" | 50 #include "ui/views/mouse_watcher_view_host.h" |
| 51 #include "ui/views/rect_based_targeting_utils.h" |
50 #include "ui/views/view_model_utils.h" | 52 #include "ui/views/view_model_utils.h" |
51 #include "ui/views/widget/root_view.h" | 53 #include "ui/views/widget/root_view.h" |
52 #include "ui/views/widget/widget.h" | 54 #include "ui/views/widget/widget.h" |
53 #include "ui/views/window/non_client_view.h" | 55 #include "ui/views/window/non_client_view.h" |
54 | 56 |
55 #if defined(OS_WIN) | 57 #if defined(OS_WIN) |
56 #include "ui/gfx/win/hwnd_util.h" | 58 #include "ui/gfx/win/hwnd_util.h" |
57 #include "ui/views/widget/monitor_win.h" | 59 #include "ui/views/widget/monitor_win.h" |
58 #include "ui/views/win/hwnd_util.h" | 60 #include "ui/views/win/hwnd_util.h" |
59 #include "win8/util/win8_util.h" | 61 #include "win8/util/win8_util.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 304 |
303 // Set the background offset used to match the background image to the frame | 305 // Set the background offset used to match the background image to the frame |
304 // image. | 306 // image. |
305 void set_background_offset(const gfx::Point& offset) { | 307 void set_background_offset(const gfx::Point& offset) { |
306 background_offset_ = offset; | 308 background_offset_ = offset; |
307 } | 309 } |
308 | 310 |
309 protected: | 311 protected: |
310 // Overridden from views::View: | 312 // Overridden from views::View: |
311 virtual bool HasHitTestMask() const OVERRIDE; | 313 virtual bool HasHitTestMask() const OVERRIDE; |
312 virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; | 314 virtual void GetHitTestMask(gfx::Path* path, |
| 315 HitTestSource source = HIT_TEST_SOURCE_MOUSE) const OVERRIDE; |
313 #if defined(OS_WIN) | 316 #if defined(OS_WIN) |
314 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 317 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
315 #endif | 318 #endif |
316 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 319 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
317 | 320 |
318 // Overridden from ui::EventHandler: | 321 // Overridden from ui::EventHandler: |
319 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 322 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
320 | 323 |
321 private: | 324 private: |
322 bool ShouldUseNativeFrame() const; | 325 bool ShouldUseNativeFrame() const; |
(...skipping 26 matching lines...) Expand all Loading... |
349 *destroyed_ = true; | 352 *destroyed_ = true; |
350 } | 353 } |
351 | 354 |
352 bool NewTabButton::HasHitTestMask() const { | 355 bool NewTabButton::HasHitTestMask() const { |
353 // When the button is sized to the top of the tab strip we want the user to | 356 // When the button is sized to the top of the tab strip we want the user to |
354 // be able to click on complete bounds, and so don't return a custom hit | 357 // be able to click on complete bounds, and so don't return a custom hit |
355 // mask. | 358 // mask. |
356 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); | 359 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); |
357 } | 360 } |
358 | 361 |
359 void NewTabButton::GetHitTestMask(gfx::Path* path) const { | 362 void NewTabButton::GetHitTestMask(gfx::Path* path, HitTestSource source) const { |
360 DCHECK(path); | 363 DCHECK(path); |
361 | 364 |
362 SkScalar w = SkIntToScalar(width()); | 365 SkScalar w = SkIntToScalar(width()); |
363 SkScalar v_offset = SkIntToScalar(newtab_button_v_offset()); | 366 SkScalar v_offset = SkIntToScalar(newtab_button_v_offset()); |
364 | 367 |
365 // These values are defined by the shape of the new tab image. Should that | 368 // These values are defined by the shape of the new tab image. Should that |
366 // image ever change, these values will need to be updated. They're so | 369 // image ever change, these values will need to be updated. They're so |
367 // custom it's not really worth defining constants for. | 370 // custom it's not really worth defining constants for. |
368 // These values are correct for regular and USE_ASH versions of the image. | 371 // These values are correct for regular and USE_ASH versions of the image. |
369 path->moveTo(0, v_offset + 1); | 372 path->moveTo(0, v_offset + 1); |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 910 |
908 bool TabStrip::IsTabStripCloseable() const { | 911 bool TabStrip::IsTabStripCloseable() const { |
909 return !IsDragSessionActive(); | 912 return !IsDragSessionActive(); |
910 } | 913 } |
911 | 914 |
912 void TabStrip::UpdateLoadingAnimations() { | 915 void TabStrip::UpdateLoadingAnimations() { |
913 controller_->UpdateLoadingAnimations(); | 916 controller_->UpdateLoadingAnimations(); |
914 } | 917 } |
915 | 918 |
916 bool TabStrip::IsPositionInWindowCaption(const gfx::Point& point) { | 919 bool TabStrip::IsPositionInWindowCaption(const gfx::Point& point) { |
917 views::View* v = GetEventHandlerForPoint(point); | 920 return IsRectInWindowCaption(gfx::Rect(point, gfx::Size(1, 1))); |
| 921 } |
| 922 |
| 923 bool TabStrip::IsRectInWindowCaption(const gfx::Rect& rect) { |
| 924 views::View* v = GetEventHandlerForRect(rect); |
918 | 925 |
919 // If there is no control at this location, claim the hit was in the title | 926 // If there is no control at this location, claim the hit was in the title |
920 // bar to get a move action. | 927 // bar to get a move action. |
921 if (v == this) | 928 if (v == this) |
922 return true; | 929 return true; |
923 | 930 |
924 // Check to see if the point is within the non-button parts of the new tab | 931 // Check to see if the rect intersects the non-button parts of the new tab |
925 // button. The button has a non-rectangular shape, so if it's not in the | 932 // button. The button has a non-rectangular shape, so if it's not in the |
926 // visual portions of the button we treat it as a click to the caption. | 933 // visual portions of the button we treat it as a click to the caption. |
927 gfx::Point point_in_newtab_coords(point); | 934 gfx::RectF rect_in_newtab_coords_f(rect); |
928 View::ConvertPointToTarget(this, newtab_button_, &point_in_newtab_coords); | 935 View::ConvertRectToTarget(this, newtab_button_, &rect_in_newtab_coords_f); |
929 if (newtab_button_->GetLocalBounds().Contains(point_in_newtab_coords) && | 936 gfx::Rect rect_in_newtab_coords = gfx::ToEnclosingRect( |
930 !newtab_button_->HitTestPoint(point_in_newtab_coords)) { | 937 rect_in_newtab_coords_f); |
| 938 if (newtab_button_->GetLocalBounds().Intersects(rect_in_newtab_coords) && |
| 939 !newtab_button_->HitTestRect(rect_in_newtab_coords)) |
931 return true; | 940 return true; |
932 } | |
933 | 941 |
934 // All other regions, including the new Tab button, should be considered part | 942 // All other regions, including the new Tab button, should be considered part |
935 // of the containing Window's client area so that regular events can be | 943 // of the containing Window's client area so that regular events can be |
936 // processed for them. | 944 // processed for them. |
937 return false; | 945 return false; |
938 } | 946 } |
939 | 947 |
940 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { | 948 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { |
941 for (int i = 0; i < tab_count(); ++i) | 949 for (int i = 0; i < tab_count(); ++i) |
942 tab_at(i)->set_background_offset(offset); | 950 tab_at(i)->set_background_offset(offset); |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 | 1426 |
1419 controller()->PerformDrop(drop_before, drop_index, url); | 1427 controller()->PerformDrop(drop_before, drop_index, url); |
1420 | 1428 |
1421 return GetDropEffect(event); | 1429 return GetDropEffect(event); |
1422 } | 1430 } |
1423 | 1431 |
1424 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { | 1432 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { |
1425 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 1433 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; |
1426 } | 1434 } |
1427 | 1435 |
1428 views::View* TabStrip::GetEventHandlerForPoint(const gfx::Point& point) { | 1436 views::View* TabStrip::GetEventHandlerForRect(const gfx::Rect& rect) { |
| 1437 if (!views::UsePointBasedTargeting(rect)) |
| 1438 return View::GetEventHandlerForRect(rect); |
| 1439 const gfx::Point point(rect.CenterPoint()); |
| 1440 |
1429 if (!touch_layout_.get()) { | 1441 if (!touch_layout_.get()) { |
1430 // Return any view that isn't a Tab or this TabStrip immediately. We don't | 1442 // Return any view that isn't a Tab or this TabStrip immediately. We don't |
1431 // want to interfere. | 1443 // want to interfere. |
1432 views::View* v = View::GetEventHandlerForPoint(point); | 1444 views::View* v = View::GetEventHandlerForRect(rect); |
1433 if (v && v != this && strcmp(v->GetClassName(), Tab::kViewClassName)) | 1445 if (v && v != this && strcmp(v->GetClassName(), Tab::kViewClassName)) |
1434 return v; | 1446 return v; |
1435 | 1447 |
1436 views::View* tab = FindTabHitByPoint(point); | 1448 views::View* tab = FindTabHitByPoint(point); |
1437 if (tab) | 1449 if (tab) |
1438 return tab; | 1450 return tab; |
1439 } else { | 1451 } else { |
1440 if (newtab_button_->visible()) { | 1452 if (newtab_button_->visible()) { |
1441 views::View* view = | 1453 views::View* view = |
1442 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 1454 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2714 if (!adjust_layout_) | 2726 if (!adjust_layout_) |
2715 return false; | 2727 return false; |
2716 | 2728 |
2717 #if !defined(OS_CHROMEOS) | 2729 #if !defined(OS_CHROMEOS) |
2718 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2730 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
2719 return false; | 2731 return false; |
2720 #endif | 2732 #endif |
2721 | 2733 |
2722 return true; | 2734 return true; |
2723 } | 2735 } |
OLD | NEW |