| 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 29 matching lines...) Expand all Loading... |
| 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/rect_conversions.h" |
| 47 #include "ui/gfx/screen.h" | 47 #include "ui/gfx/screen.h" |
| 48 #include "ui/gfx/size.h" | 48 #include "ui/gfx/size.h" |
| 49 #include "ui/views/controls/image_view.h" | 49 #include "ui/views/controls/image_view.h" |
| 50 #include "ui/views/masked_view_targeter.h" | |
| 51 #include "ui/views/mouse_watcher_view_host.h" | 50 #include "ui/views/mouse_watcher_view_host.h" |
| 52 #include "ui/views/rect_based_targeting_utils.h" | 51 #include "ui/views/rect_based_targeting_utils.h" |
| 53 #include "ui/views/view_model_utils.h" | 52 #include "ui/views/view_model_utils.h" |
| 54 #include "ui/views/widget/root_view.h" | 53 #include "ui/views/widget/root_view.h" |
| 55 #include "ui/views/widget/widget.h" | 54 #include "ui/views/widget/widget.h" |
| 56 #include "ui/views/window/non_client_view.h" | 55 #include "ui/views/window/non_client_view.h" |
| 57 | 56 |
| 58 #if defined(OS_WIN) | 57 #if defined(OS_WIN) |
| 59 #include "ui/gfx/win/hwnd_util.h" | 58 #include "ui/gfx/win/hwnd_util.h" |
| 60 #include "ui/views/widget/monitor_win.h" | 59 #include "ui/views/widget/monitor_win.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 *destroyed_ = true; | 288 *destroyed_ = true; |
| 290 } | 289 } |
| 291 | 290 |
| 292 bool NewTabButton::HasHitTestMask() const { | 291 bool NewTabButton::HasHitTestMask() const { |
| 293 // When the button is sized to the top of the tab strip we want the user to | 292 // When the button is sized to the top of the tab strip we want the user to |
| 294 // be able to click on complete bounds, and so don't return a custom hit | 293 // be able to click on complete bounds, and so don't return a custom hit |
| 295 // mask. | 294 // mask. |
| 296 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); | 295 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); |
| 297 } | 296 } |
| 298 | 297 |
| 299 // TODO(tdanderson): Move the implementation into View::HitTestRect() and | |
| 300 // delete this function. See crbug.com/377527. | |
| 301 void NewTabButton::GetHitTestMask(HitTestSource source, gfx::Path* path) const { | 298 void NewTabButton::GetHitTestMask(HitTestSource source, gfx::Path* path) const { |
| 302 const ui::EventTargeter* targeter = GetEventTargeter(); | 299 DCHECK(path); |
| 303 DCHECK(targeter); | 300 |
| 304 static_cast<const views::MaskedViewTargeter*>(targeter) | 301 SkScalar w = SkIntToScalar(width()); |
| 305 ->GetHitTestMask(this, path); | 302 SkScalar v_offset = SkIntToScalar(TabStrip::kNewTabButtonVerticalOffset); |
| 303 |
| 304 // These values are defined by the shape of the new tab image. Should that |
| 305 // image ever change, these values will need to be updated. They're so |
| 306 // custom it's not really worth defining constants for. |
| 307 // These values are correct for regular and USE_ASH versions of the image. |
| 308 path->moveTo(0, v_offset + 1); |
| 309 path->lineTo(w - 7, v_offset + 1); |
| 310 path->lineTo(w - 4, v_offset + 4); |
| 311 path->lineTo(w, v_offset + 16); |
| 312 path->lineTo(w - 1, v_offset + 17); |
| 313 path->lineTo(7, v_offset + 17); |
| 314 path->lineTo(4, v_offset + 13); |
| 315 path->lineTo(0, v_offset + 1); |
| 316 path->close(); |
| 306 } | 317 } |
| 307 | 318 |
| 308 #if defined(OS_WIN) | 319 #if defined(OS_WIN) |
| 309 void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { | 320 void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 310 if (event.IsOnlyRightMouseButton()) { | 321 if (event.IsOnlyRightMouseButton()) { |
| 311 gfx::Point point = event.location(); | 322 gfx::Point point = event.location(); |
| 312 views::View::ConvertPointToScreen(this, &point); | 323 views::View::ConvertPointToScreen(this, &point); |
| 313 bool destroyed = false; | 324 bool destroyed = false; |
| 314 destroyed_ = &destroyed; | 325 destroyed_ = &destroyed; |
| 315 gfx::ShowSystemMenuAtPoint(views::HWNDForView(this), point); | 326 gfx::ShowSystemMenuAtPoint(views::HWNDForView(this), point); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 451 |
| 441 gfx::ImageSkia NewTabButton::GetImageForScale(float scale) const { | 452 gfx::ImageSkia NewTabButton::GetImageForScale(float scale) const { |
| 442 if (!hover_animation_->is_animating()) | 453 if (!hover_animation_->is_animating()) |
| 443 return GetImageForState(state(), scale); | 454 return GetImageForState(state(), scale); |
| 444 return gfx::ImageSkiaOperations::CreateBlendedImage( | 455 return gfx::ImageSkiaOperations::CreateBlendedImage( |
| 445 GetImageForState(views::CustomButton::STATE_NORMAL, scale), | 456 GetImageForState(views::CustomButton::STATE_NORMAL, scale), |
| 446 GetImageForState(views::CustomButton::STATE_HOVERED, scale), | 457 GetImageForState(views::CustomButton::STATE_HOVERED, scale), |
| 447 hover_animation_->GetCurrentValue()); | 458 hover_animation_->GetCurrentValue()); |
| 448 } | 459 } |
| 449 | 460 |
| 450 // Used to define the custom hit-test region of the new tab button | |
| 451 // for the purposes of event targeting. | |
| 452 class NewTabButtonTargeter : public views::MaskedViewTargeter { | |
| 453 public: | |
| 454 explicit NewTabButtonTargeter(views::View* new_tab_button) | |
| 455 : views::MaskedViewTargeter(new_tab_button) {} | |
| 456 virtual ~NewTabButtonTargeter() {} | |
| 457 | |
| 458 private: | |
| 459 // views::MaskedViewTargeter: | |
| 460 virtual bool GetHitTestMask(const views::View* view, | |
| 461 gfx::Path* mask) const OVERRIDE { | |
| 462 DCHECK(mask); | |
| 463 DCHECK_EQ(view, masked_view()); | |
| 464 | |
| 465 SkScalar w = SkIntToScalar(view->width()); | |
| 466 SkScalar v_offset = SkIntToScalar(TabStrip::kNewTabButtonVerticalOffset); | |
| 467 | |
| 468 // These values are defined by the shape of the new tab image. Should that | |
| 469 // image ever change, these values will need to be updated. They're so | |
| 470 // custom it's not really worth defining constants for. | |
| 471 // These values are correct for regular and USE_ASH versions of the image. | |
| 472 mask->moveTo(0, v_offset + 1); | |
| 473 mask->lineTo(w - 7, v_offset + 1); | |
| 474 mask->lineTo(w - 4, v_offset + 4); | |
| 475 mask->lineTo(w, v_offset + 16); | |
| 476 mask->lineTo(w - 1, v_offset + 17); | |
| 477 mask->lineTo(7, v_offset + 17); | |
| 478 mask->lineTo(4, v_offset + 13); | |
| 479 mask->lineTo(0, v_offset + 1); | |
| 480 mask->close(); | |
| 481 | |
| 482 return true; | |
| 483 } | |
| 484 | |
| 485 DISALLOW_COPY_AND_ASSIGN(NewTabButtonTargeter); | |
| 486 }; | |
| 487 | |
| 488 /////////////////////////////////////////////////////////////////////////////// | 461 /////////////////////////////////////////////////////////////////////////////// |
| 489 // TabStrip::RemoveTabDelegate | 462 // TabStrip::RemoveTabDelegate |
| 490 // | 463 // |
| 491 // AnimationDelegate used when removing a tab. Does the necessary cleanup when | 464 // AnimationDelegate used when removing a tab. Does the necessary cleanup when |
| 492 // done. | 465 // done. |
| 493 class TabStrip::RemoveTabDelegate : public TabAnimationDelegate { | 466 class TabStrip::RemoveTabDelegate : public TabAnimationDelegate { |
| 494 public: | 467 public: |
| 495 RemoveTabDelegate(TabStrip* tab_strip, Tab* tab); | 468 RemoveTabDelegate(TabStrip* tab_strip, Tab* tab); |
| 496 | 469 |
| 497 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; | 470 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 kNewTabButtonAssetHeight + | 1463 kNewTabButtonAssetHeight + |
| 1491 kNewTabButtonVerticalOffset); | 1464 kNewTabButtonVerticalOffset); |
| 1492 newtab_button_ = new NewTabButton(this, this); | 1465 newtab_button_ = new NewTabButton(this, this); |
| 1493 newtab_button_->SetTooltipText( | 1466 newtab_button_->SetTooltipText( |
| 1494 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); | 1467 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); |
| 1495 newtab_button_->SetAccessibleName( | 1468 newtab_button_->SetAccessibleName( |
| 1496 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); | 1469 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); |
| 1497 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, | 1470 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, |
| 1498 views::ImageButton::ALIGN_BOTTOM); | 1471 views::ImageButton::ALIGN_BOTTOM); |
| 1499 AddChildView(newtab_button_); | 1472 AddChildView(newtab_button_); |
| 1500 newtab_button_->SetEventTargeter( | |
| 1501 scoped_ptr<ui::EventTargeter>(new NewTabButtonTargeter(newtab_button_))); | |
| 1502 | |
| 1503 if (drop_indicator_width == 0) { | 1473 if (drop_indicator_width == 0) { |
| 1504 // Direction doesn't matter, both images are the same size. | 1474 // Direction doesn't matter, both images are the same size. |
| 1505 gfx::ImageSkia* drop_image = GetDropArrowImage(true); | 1475 gfx::ImageSkia* drop_image = GetDropArrowImage(true); |
| 1506 drop_indicator_width = drop_image->width(); | 1476 drop_indicator_width = drop_image->width(); |
| 1507 drop_indicator_height = drop_image->height(); | 1477 drop_indicator_height = drop_image->height(); |
| 1508 } | 1478 } |
| 1509 } | 1479 } |
| 1510 | 1480 |
| 1511 Tab* TabStrip::CreateTab() { | 1481 Tab* TabStrip::CreateTab() { |
| 1512 Tab* tab = new Tab(this); | 1482 Tab* tab = new Tab(this); |
| (...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2716 action = TouchUMA::GESTURE_TABSWITCH_TAP; | 2686 action = TouchUMA::GESTURE_TABSWITCH_TAP; |
| 2717 TouchUMA::RecordGestureAction(action); | 2687 TouchUMA::RecordGestureAction(action); |
| 2718 break; | 2688 break; |
| 2719 } | 2689 } |
| 2720 | 2690 |
| 2721 default: | 2691 default: |
| 2722 break; | 2692 break; |
| 2723 } | 2693 } |
| 2724 event->SetHandled(); | 2694 event->SetHandled(); |
| 2725 } | 2695 } |
| OLD | NEW |