| 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" |
| 50 #include "ui/views/mouse_watcher_view_host.h" | 51 #include "ui/views/mouse_watcher_view_host.h" |
| 51 #include "ui/views/rect_based_targeting_utils.h" | 52 #include "ui/views/rect_based_targeting_utils.h" |
| 52 #include "ui/views/view_model_utils.h" | 53 #include "ui/views/view_model_utils.h" |
| 53 #include "ui/views/widget/root_view.h" | 54 #include "ui/views/widget/root_view.h" |
| 54 #include "ui/views/widget/widget.h" | 55 #include "ui/views/widget/widget.h" |
| 55 #include "ui/views/window/non_client_view.h" | 56 #include "ui/views/window/non_client_view.h" |
| 56 | 57 |
| 57 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 58 #include "ui/gfx/win/hwnd_util.h" | 59 #include "ui/gfx/win/hwnd_util.h" |
| 59 #include "ui/views/widget/monitor_win.h" | 60 #include "ui/views/widget/monitor_win.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 *destroyed_ = true; | 260 *destroyed_ = true; |
| 260 } | 261 } |
| 261 | 262 |
| 262 bool NewTabButton::HasHitTestMask() const { | 263 bool NewTabButton::HasHitTestMask() const { |
| 263 // When the button is sized to the top of the tab strip we want the user to | 264 // When the button is sized to the top of the tab strip we want the user to |
| 264 // be able to click on complete bounds, and so don't return a custom hit | 265 // be able to click on complete bounds, and so don't return a custom hit |
| 265 // mask. | 266 // mask. |
| 266 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); | 267 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); |
| 267 } | 268 } |
| 268 | 269 |
| 270 // TODO(tdanderson): Move the implementation into View::HitTestRect() and |
| 271 // delete this function. See crbug.com/377527. |
| 269 void NewTabButton::GetHitTestMask(HitTestSource source, gfx::Path* path) const { | 272 void NewTabButton::GetHitTestMask(HitTestSource source, gfx::Path* path) const { |
| 270 DCHECK(path); | 273 const ui::EventTargeter* targeter = GetEventTargeter(); |
| 271 | 274 DCHECK(targeter); |
| 272 SkScalar w = SkIntToScalar(width()); | 275 static_cast<const views::MaskedViewTargeter*>(targeter) |
| 273 SkScalar v_offset = SkIntToScalar(kNewTabButtonVerticalOffset); | 276 ->GetHitTestMask(this, path); |
| 274 | |
| 275 // These values are defined by the shape of the new tab image. Should that | |
| 276 // image ever change, these values will need to be updated. They're so | |
| 277 // custom it's not really worth defining constants for. | |
| 278 // These values are correct for regular and USE_ASH versions of the image. | |
| 279 path->moveTo(0, v_offset + 1); | |
| 280 path->lineTo(w - 7, v_offset + 1); | |
| 281 path->lineTo(w - 4, v_offset + 4); | |
| 282 path->lineTo(w, v_offset + 16); | |
| 283 path->lineTo(w - 1, v_offset + 17); | |
| 284 path->lineTo(7, v_offset + 17); | |
| 285 path->lineTo(4, v_offset + 13); | |
| 286 path->lineTo(0, v_offset + 1); | |
| 287 path->close(); | |
| 288 } | 277 } |
| 289 | 278 |
| 290 #if defined(OS_WIN) | 279 #if defined(OS_WIN) |
| 291 void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { | 280 void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 292 if (event.IsOnlyRightMouseButton()) { | 281 if (event.IsOnlyRightMouseButton()) { |
| 293 gfx::Point point = event.location(); | 282 gfx::Point point = event.location(); |
| 294 views::View::ConvertPointToScreen(this, &point); | 283 views::View::ConvertPointToScreen(this, &point); |
| 295 bool destroyed = false; | 284 bool destroyed = false; |
| 296 destroyed_ = &destroyed; | 285 destroyed_ = &destroyed; |
| 297 gfx::ShowSystemMenuAtPoint(views::HWNDForView(this), point); | 286 gfx::ShowSystemMenuAtPoint(views::HWNDForView(this), point); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 410 |
| 422 gfx::ImageSkia NewTabButton::GetImageForScale(float scale) const { | 411 gfx::ImageSkia NewTabButton::GetImageForScale(float scale) const { |
| 423 if (!hover_animation_->is_animating()) | 412 if (!hover_animation_->is_animating()) |
| 424 return GetImageForState(state(), scale); | 413 return GetImageForState(state(), scale); |
| 425 return gfx::ImageSkiaOperations::CreateBlendedImage( | 414 return gfx::ImageSkiaOperations::CreateBlendedImage( |
| 426 GetImageForState(views::CustomButton::STATE_NORMAL, scale), | 415 GetImageForState(views::CustomButton::STATE_NORMAL, scale), |
| 427 GetImageForState(views::CustomButton::STATE_HOVERED, scale), | 416 GetImageForState(views::CustomButton::STATE_HOVERED, scale), |
| 428 hover_animation_->GetCurrentValue()); | 417 hover_animation_->GetCurrentValue()); |
| 429 } | 418 } |
| 430 | 419 |
| 420 // Used to define the custom hit-test region of the new tab button |
| 421 // for the purposes of event targeting. |
| 422 class NewTabButtonTargeter : public views::MaskedViewTargeter { |
| 423 public: |
| 424 explicit NewTabButtonTargeter(views::View* new_tab_button) |
| 425 : views::MaskedViewTargeter(new_tab_button) {} |
| 426 virtual ~NewTabButtonTargeter() {} |
| 427 |
| 428 private: |
| 429 // views::MaskedViewTargeter: |
| 430 virtual bool GetHitTestMask(const views::View* view, |
| 431 gfx::Path* mask) const OVERRIDE { |
| 432 DCHECK(mask); |
| 433 |
| 434 SkScalar w = SkIntToScalar(view->width()); |
| 435 SkScalar v_offset = SkIntToScalar(kNewTabButtonVerticalOffset); |
| 436 |
| 437 // These values are defined by the shape of the new tab image. Should that |
| 438 // image ever change, these values will need to be updated. They're so |
| 439 // custom it's not really worth defining constants for. |
| 440 // These values are correct for regular and USE_ASH versions of the image. |
| 441 mask->moveTo(0, v_offset + 1); |
| 442 mask->lineTo(w - 7, v_offset + 1); |
| 443 mask->lineTo(w - 4, v_offset + 4); |
| 444 mask->lineTo(w, v_offset + 16); |
| 445 mask->lineTo(w - 1, v_offset + 17); |
| 446 mask->lineTo(7, v_offset + 17); |
| 447 mask->lineTo(4, v_offset + 13); |
| 448 mask->lineTo(0, v_offset + 1); |
| 449 mask->close(); |
| 450 |
| 451 return true; |
| 452 } |
| 453 |
| 454 DISALLOW_COPY_AND_ASSIGN(NewTabButtonTargeter); |
| 455 }; |
| 456 |
| 431 /////////////////////////////////////////////////////////////////////////////// | 457 /////////////////////////////////////////////////////////////////////////////// |
| 432 // TabStrip::RemoveTabDelegate | 458 // TabStrip::RemoveTabDelegate |
| 433 // | 459 // |
| 434 // AnimationDelegate used when removing a tab. Does the necessary cleanup when | 460 // AnimationDelegate used when removing a tab. Does the necessary cleanup when |
| 435 // done. | 461 // done. |
| 436 class TabStrip::RemoveTabDelegate | 462 class TabStrip::RemoveTabDelegate |
| 437 : public views::BoundsAnimator::OwnedAnimationDelegate { | 463 : public views::BoundsAnimator::OwnedAnimationDelegate { |
| 438 public: | 464 public: |
| 439 RemoveTabDelegate(TabStrip* tab_strip, Tab* tab); | 465 RemoveTabDelegate(TabStrip* tab_strip, Tab* tab); |
| 440 | 466 |
| (...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 kNewTabButtonAssetHeight + | 1568 kNewTabButtonAssetHeight + |
| 1543 kNewTabButtonVerticalOffset); | 1569 kNewTabButtonVerticalOffset); |
| 1544 newtab_button_ = new NewTabButton(this, this); | 1570 newtab_button_ = new NewTabButton(this, this); |
| 1545 newtab_button_->SetTooltipText( | 1571 newtab_button_->SetTooltipText( |
| 1546 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); | 1572 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); |
| 1547 newtab_button_->SetAccessibleName( | 1573 newtab_button_->SetAccessibleName( |
| 1548 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); | 1574 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); |
| 1549 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, | 1575 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, |
| 1550 views::ImageButton::ALIGN_BOTTOM); | 1576 views::ImageButton::ALIGN_BOTTOM); |
| 1551 AddChildView(newtab_button_); | 1577 AddChildView(newtab_button_); |
| 1578 newtab_button_->SetEventTargeter( |
| 1579 scoped_ptr<ui::EventTargeter>(new NewTabButtonTargeter(newtab_button_))); |
| 1580 |
| 1552 if (drop_indicator_width == 0) { | 1581 if (drop_indicator_width == 0) { |
| 1553 // Direction doesn't matter, both images are the same size. | 1582 // Direction doesn't matter, both images are the same size. |
| 1554 gfx::ImageSkia* drop_image = GetDropArrowImage(true); | 1583 gfx::ImageSkia* drop_image = GetDropArrowImage(true); |
| 1555 drop_indicator_width = drop_image->width(); | 1584 drop_indicator_width = drop_image->width(); |
| 1556 drop_indicator_height = drop_image->height(); | 1585 drop_indicator_height = drop_image->height(); |
| 1557 } | 1586 } |
| 1558 } | 1587 } |
| 1559 | 1588 |
| 1560 Tab* TabStrip::CreateTab() { | 1589 Tab* TabStrip::CreateTab() { |
| 1561 Tab* tab = new Tab(this); | 1590 Tab* tab = new Tab(this); |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2632 if (value == reset_to_shrink_on_exit_) | 2661 if (value == reset_to_shrink_on_exit_) |
| 2633 return; | 2662 return; |
| 2634 | 2663 |
| 2635 reset_to_shrink_on_exit_ = value; | 2664 reset_to_shrink_on_exit_ = value; |
| 2636 // Add an observer so we know when the mouse moves out of the tabstrip. | 2665 // Add an observer so we know when the mouse moves out of the tabstrip. |
| 2637 if (reset_to_shrink_on_exit_) | 2666 if (reset_to_shrink_on_exit_) |
| 2638 AddMessageLoopObserver(); | 2667 AddMessageLoopObserver(); |
| 2639 else | 2668 else |
| 2640 RemoveMessageLoopObserver(); | 2669 RemoveMessageLoopObserver(); |
| 2641 } | 2670 } |
| OLD | NEW |