| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/views/corewm/tooltip_controller.h" | 5 #include "ui/views/corewm/tooltip_controller.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/aura/client/cursor_client.h" | 8 #include "ui/aura/client/cursor_client.h" |
| 9 #include "ui/aura/client/screen_position_client.h" | 9 #include "ui/aura/client/screen_position_client.h" |
| 10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 gfx::Point v2_point(1, 1); | 384 gfx::Point v2_point(1, 1); |
| 385 View::ConvertPointToWidget(v2, &v2_point); | 385 View::ConvertPointToWidget(v2, &v2_point); |
| 386 generator_->MoveMouseRelativeTo(GetWindow(), v2_point); | 386 generator_->MoveMouseRelativeTo(GetWindow(), v2_point); |
| 387 generator_->MoveMouseRelativeTo(GetWindow(), v1_point); | 387 generator_->MoveMouseRelativeTo(GetWindow(), v1_point); |
| 388 | 388 |
| 389 helper_->FireTooltipTimer(); | 389 helper_->FireTooltipTimer(); |
| 390 EXPECT_TRUE(helper_->IsTooltipVisible()); | 390 EXPECT_TRUE(helper_->IsTooltipVisible()); |
| 391 EXPECT_EQ(v1_tt, helper_->GetTooltipText()); | 391 EXPECT_EQ(v1_tt, helper_->GetTooltipText()); |
| 392 } | 392 } |
| 393 | 393 |
| 394 TEST_F(TooltipControllerTest, TooltipPositionChangesOnTwoViewsWithSameLabel) { |
| 395 // Owned by |view_|. |
| 396 TooltipTestView* v1 = new TooltipTestView; |
| 397 TooltipTestView* v2 = new TooltipTestView; |
| 398 view_->AddChildView(v1); |
| 399 view_->AddChildView(v2); |
| 400 const base::string16 reference_string(base::ASCIIToUTF16( |
| 401 "Identical Tooltip Text")); |
| 402 v1->set_tooltip_text(reference_string); |
| 403 v2->set_tooltip_text(reference_string); |
| 404 |
| 405 gfx::Rect view_bounds(view_->GetLocalBounds()); |
| 406 view_bounds.set_height(view_bounds.height() / 2); |
| 407 v1->SetBoundsRect(view_bounds); |
| 408 view_bounds.set_y(view_bounds.height()); |
| 409 v2->SetBoundsRect(view_bounds); |
| 410 |
| 411 gfx::Point center = v1->bounds().CenterPoint(); |
| 412 generator_->MoveMouseRelativeTo(GetWindow(), center); |
| 413 helper_->FireTooltipTimer(); |
| 414 EXPECT_TRUE(helper_->IsTooltipVisible()); |
| 415 EXPECT_EQ(reference_string, helper_->GetTooltipText()); |
| 416 gfx::Point tooltip_bounds1 = helper_->GetTooltipPosition(); |
| 417 |
| 418 center = v2->bounds().CenterPoint(); |
| 419 generator_->MoveMouseRelativeTo(GetWindow(), center); |
| 420 helper_->FireTooltipTimer(); |
| 421 EXPECT_TRUE(helper_->IsTooltipVisible()); |
| 422 EXPECT_EQ(reference_string, helper_->GetTooltipText()); |
| 423 gfx::Point tooltip_bounds2 = helper_->GetTooltipPosition(); |
| 424 |
| 425 EXPECT_NE(tooltip_bounds1, gfx::Point()); |
| 426 EXPECT_NE(tooltip_bounds2, gfx::Point()); |
| 427 EXPECT_NE(tooltip_bounds1, tooltip_bounds2); |
| 428 } |
| 429 |
| 394 namespace { | 430 namespace { |
| 395 | 431 |
| 396 // Returns the index of |window| in its parent's children. | 432 // Returns the index of |window| in its parent's children. |
| 397 int IndexInParent(const aura::Window* window) { | 433 int IndexInParent(const aura::Window* window) { |
| 398 aura::Window::Windows::const_iterator i = | 434 aura::Window::Windows::const_iterator i = |
| 399 std::find(window->parent()->children().begin(), | 435 std::find(window->parent()->children().begin(), |
| 400 window->parent()->children().end(), | 436 window->parent()->children().end(), |
| 401 window); | 437 window); |
| 402 return i == window->parent()->children().end() ? -1 : | 438 return i == window->parent()->children().end() ? -1 : |
| 403 static_cast<int>(i - window->parent()->children().begin()); | 439 static_cast<int>(i - window->parent()->children().begin()); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 } | 708 } |
| 673 virtual void Show() OVERRIDE { | 709 virtual void Show() OVERRIDE { |
| 674 is_visible_ = true; | 710 is_visible_ = true; |
| 675 } | 711 } |
| 676 virtual void Hide() OVERRIDE { | 712 virtual void Hide() OVERRIDE { |
| 677 is_visible_ = false; | 713 is_visible_ = false; |
| 678 } | 714 } |
| 679 virtual bool IsVisible() OVERRIDE { | 715 virtual bool IsVisible() OVERRIDE { |
| 680 return is_visible_; | 716 return is_visible_; |
| 681 } | 717 } |
| 718 virtual gfx::Point GetTooltipPosition() OVERRIDE { |
| 719 return gfx::Point(); |
| 720 } |
| 682 | 721 |
| 683 private: | 722 private: |
| 684 bool is_visible_; | 723 bool is_visible_; |
| 685 base::string16 tooltip_text_; | 724 base::string16 tooltip_text_; |
| 686 | 725 |
| 687 DISALLOW_COPY_AND_ASSIGN(TestTooltip); | 726 DISALLOW_COPY_AND_ASSIGN(TestTooltip); |
| 688 }; | 727 }; |
| 689 | 728 |
| 690 } // namespace | 729 } // namespace |
| 691 | 730 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 // the tooltip window is closed. | 798 // the tooltip window is closed. |
| 760 ui::CancelModeEvent event; | 799 ui::CancelModeEvent event; |
| 761 helper_->controller()->OnCancelMode(&event); | 800 helper_->controller()->OnCancelMode(&event); |
| 762 EXPECT_FALSE(helper_->IsTooltipVisible()); | 801 EXPECT_FALSE(helper_->IsTooltipVisible()); |
| 763 EXPECT_TRUE(helper_->GetTooltipWindow() == NULL); | 802 EXPECT_TRUE(helper_->GetTooltipWindow() == NULL); |
| 764 } | 803 } |
| 765 | 804 |
| 766 } // namespace test | 805 } // namespace test |
| 767 } // namespace corewm | 806 } // namespace corewm |
| 768 } // namespace views | 807 } // namespace views |
| OLD | NEW |