| 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 "ui/views/controls/scroll_view.h" |     5 #include "ui/views/controls/scroll_view.h" | 
|     6  |     6  | 
|     7 #include "base/macros.h" |     7 #include "base/macros.h" | 
|     8 #include "base/run_loop.h" |     8 #include "base/run_loop.h" | 
|     9 #include "base/test/test_timeouts.h" |     9 #include "base/test/test_timeouts.h" | 
|    10 #include "base/threading/thread_task_runner_handle.h" |    10 #include "base/threading/thread_task_runner_handle.h" | 
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   160  private: |   160  private: | 
|   161   // Disable overlay scrollers by default. This needs to be set before |   161   // Disable overlay scrollers by default. This needs to be set before | 
|   162   // |scroll_view_| is initialized, otherwise scrollers will try to animate to |   162   // |scroll_view_| is initialized, otherwise scrollers will try to animate to | 
|   163   // change modes, which requires a MessageLoop to exist. Tests should only |   163   // change modes, which requires a MessageLoop to exist. Tests should only | 
|   164   // modify this via SetOverlayScrollersEnabled(). |   164   // modify this via SetOverlayScrollersEnabled(). | 
|   165   std::unique_ptr<ui::test::ScopedPreferredScrollerStyle> scroller_style_ = |   165   std::unique_ptr<ui::test::ScopedPreferredScrollerStyle> scroller_style_ = | 
|   166       base::MakeUnique<ui::test::ScopedPreferredScrollerStyle>(false); |   166       base::MakeUnique<ui::test::ScopedPreferredScrollerStyle>(false); | 
|   167  |   167  | 
|   168  protected: |   168  protected: | 
|   169 #endif |   169 #endif | 
 |   170   int VerticalScrollBarWidth() { | 
 |   171     return scroll_view_.vertical_scroll_bar()->GetThickness(); | 
 |   172   } | 
 |   173  | 
 |   174   int HorizontalScrollBarHeight() { | 
 |   175     return scroll_view_.horizontal_scroll_bar()->GetThickness(); | 
 |   176   } | 
 |   177  | 
|   170   ScrollView scroll_view_; |   178   ScrollView scroll_view_; | 
|   171  |   179  | 
|   172  private: |   180  private: | 
|   173   DISALLOW_COPY_AND_ASSIGN(ScrollViewTest); |   181   DISALLOW_COPY_AND_ASSIGN(ScrollViewTest); | 
|   174 }; |   182 }; | 
|   175  |   183  | 
|   176 // Test harness that includes a Widget to help test ui::Event handling. |   184 // Test harness that includes a Widget to help test ui::Event handling. | 
|   177 class WidgetScrollViewTest : public test::WidgetTest, |   185 class WidgetScrollViewTest : public test::WidgetTest, | 
|   178                              public ui::CompositorObserver { |   186                              public ui::CompositorObserver { | 
|   179  public: |   187  public: | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   302 } |   310 } | 
|   303  |   311  | 
|   304 // Verifies the scrollbars are added as necessary. |   312 // Verifies the scrollbars are added as necessary. | 
|   305 // If on Mac, test the non-overlay scrollbars. |   313 // If on Mac, test the non-overlay scrollbars. | 
|   306 TEST_F(ScrollViewTest, ScrollBars) { |   314 TEST_F(ScrollViewTest, ScrollBars) { | 
|   307   View* contents = InstallContents(); |   315   View* contents = InstallContents(); | 
|   308  |   316  | 
|   309   // Size the contents such that vertical scrollbar is needed. |   317   // Size the contents such that vertical scrollbar is needed. | 
|   310   contents->SetBounds(0, 0, 50, 400); |   318   contents->SetBounds(0, 0, 50, 400); | 
|   311   scroll_view_.Layout(); |   319   scroll_view_.Layout(); | 
|   312   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth(), |   320   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutWidth(), | 
|   313             contents->parent()->width()); |   321             contents->parent()->width()); | 
|   314   EXPECT_EQ(100, contents->parent()->height()); |   322   EXPECT_EQ(100, contents->parent()->height()); | 
|   315   CheckScrollbarVisibility(scroll_view_, VERTICAL, true); |   323   CheckScrollbarVisibility(scroll_view_, VERTICAL, true); | 
|   316   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, false); |   324   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, false); | 
|   317   EXPECT_TRUE(!scroll_view_.horizontal_scroll_bar() || |   325   EXPECT_TRUE(!scroll_view_.horizontal_scroll_bar() || | 
|   318               !scroll_view_.horizontal_scroll_bar()->visible()); |   326               !scroll_view_.horizontal_scroll_bar()->visible()); | 
|   319   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); |   327   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); | 
|   320   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); |   328   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); | 
|   321  |   329  | 
|   322   // Size the contents such that horizontal scrollbar is needed. |   330   // Size the contents such that horizontal scrollbar is needed. | 
|   323   contents->SetBounds(0, 0, 400, 50); |   331   contents->SetBounds(0, 0, 400, 50); | 
|   324   scroll_view_.Layout(); |   332   scroll_view_.Layout(); | 
|   325   EXPECT_EQ(100, contents->parent()->width()); |   333   EXPECT_EQ(100, contents->parent()->width()); | 
|   326   EXPECT_EQ(100 - scroll_view_.GetScrollBarHeight(), |   334   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutHeight(), | 
|   327             contents->parent()->height()); |   335             contents->parent()->height()); | 
|   328   CheckScrollbarVisibility(scroll_view_, VERTICAL, false); |   336   CheckScrollbarVisibility(scroll_view_, VERTICAL, false); | 
|   329   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, true); |   337   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, true); | 
|   330  |   338  | 
|   331   // Both horizontal and vertical. |   339   // Both horizontal and vertical. | 
|   332   contents->SetBounds(0, 0, 300, 400); |   340   contents->SetBounds(0, 0, 300, 400); | 
|   333   scroll_view_.Layout(); |   341   scroll_view_.Layout(); | 
|   334   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth(), |   342   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutWidth(), | 
|   335             contents->parent()->width()); |   343             contents->parent()->width()); | 
|   336   EXPECT_EQ(100 - scroll_view_.GetScrollBarHeight(), |   344   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutHeight(), | 
|   337             contents->parent()->height()); |   345             contents->parent()->height()); | 
|   338   CheckScrollbarVisibility(scroll_view_, VERTICAL, true); |   346   CheckScrollbarVisibility(scroll_view_, VERTICAL, true); | 
|   339   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, true); |   347   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, true); | 
|   340  |   348  | 
|   341   // Add a border, test vertical scrollbar. |   349   // Add a border, test vertical scrollbar. | 
|   342   const int kTopPadding = 1; |   350   const int kTopPadding = 1; | 
|   343   const int kLeftPadding = 2; |   351   const int kLeftPadding = 2; | 
|   344   const int kBottomPadding = 3; |   352   const int kBottomPadding = 3; | 
|   345   const int kRightPadding = 4; |   353   const int kRightPadding = 4; | 
|   346   scroll_view_.SetBorder(CreateEmptyBorder(kTopPadding, kLeftPadding, |   354   scroll_view_.SetBorder(CreateEmptyBorder(kTopPadding, kLeftPadding, | 
|   347                                            kBottomPadding, kRightPadding)); |   355                                            kBottomPadding, kRightPadding)); | 
|   348   contents->SetBounds(0, 0, 50, 400); |   356   contents->SetBounds(0, 0, 50, 400); | 
|   349   scroll_view_.Layout(); |   357   scroll_view_.Layout(); | 
|   350   EXPECT_EQ( |   358   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutWidth() - kLeftPadding - | 
|   351       100 - scroll_view_.GetScrollBarWidth() - kLeftPadding - kRightPadding, |   359                 kRightPadding, | 
|   352       contents->parent()->width()); |   360             contents->parent()->width()); | 
|   353   EXPECT_EQ(100 - kTopPadding - kBottomPadding, contents->parent()->height()); |   361   EXPECT_EQ(100 - kTopPadding - kBottomPadding, contents->parent()->height()); | 
|   354   EXPECT_TRUE(!scroll_view_.horizontal_scroll_bar() || |   362   EXPECT_TRUE(!scroll_view_.horizontal_scroll_bar() || | 
|   355               !scroll_view_.horizontal_scroll_bar()->visible()); |   363               !scroll_view_.horizontal_scroll_bar()->visible()); | 
|   356   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); |   364   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); | 
|   357   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); |   365   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); | 
|   358   gfx::Rect bounds = scroll_view_.vertical_scroll_bar()->bounds(); |   366   gfx::Rect bounds = scroll_view_.vertical_scroll_bar()->bounds(); | 
|   359   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth() - kRightPadding, bounds.x()); |   367   EXPECT_EQ(100 - VerticalScrollBarWidth() - kRightPadding, bounds.x()); | 
|   360   EXPECT_EQ(100 - kRightPadding, bounds.right()); |   368   EXPECT_EQ(100 - kRightPadding, bounds.right()); | 
|   361   EXPECT_EQ(kTopPadding, bounds.y()); |   369   EXPECT_EQ(kTopPadding, bounds.y()); | 
|   362   EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); |   370   EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); | 
|   363  |   371  | 
|   364   // Horizontal with border. |   372   // Horizontal with border. | 
|   365   contents->SetBounds(0, 0, 400, 50); |   373   contents->SetBounds(0, 0, 400, 50); | 
|   366   scroll_view_.Layout(); |   374   scroll_view_.Layout(); | 
|   367   EXPECT_EQ(100 - kLeftPadding - kRightPadding, contents->parent()->width()); |   375   EXPECT_EQ(100 - kLeftPadding - kRightPadding, contents->parent()->width()); | 
|   368   EXPECT_EQ( |   376   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutHeight() - kTopPadding - | 
|   369       100 - scroll_view_.GetScrollBarHeight() - kTopPadding - kBottomPadding, |   377                 kBottomPadding, | 
|   370       contents->parent()->height()); |   378             contents->parent()->height()); | 
|   371   ASSERT_TRUE(scroll_view_.horizontal_scroll_bar() != NULL); |   379   ASSERT_TRUE(scroll_view_.horizontal_scroll_bar() != NULL); | 
|   372   EXPECT_TRUE(scroll_view_.horizontal_scroll_bar()->visible()); |   380   EXPECT_TRUE(scroll_view_.horizontal_scroll_bar()->visible()); | 
|   373   EXPECT_TRUE(!scroll_view_.vertical_scroll_bar() || |   381   EXPECT_TRUE(!scroll_view_.vertical_scroll_bar() || | 
|   374               !scroll_view_.vertical_scroll_bar()->visible()); |   382               !scroll_view_.vertical_scroll_bar()->visible()); | 
|   375   bounds = scroll_view_.horizontal_scroll_bar()->bounds(); |   383   bounds = scroll_view_.horizontal_scroll_bar()->bounds(); | 
|   376   EXPECT_EQ(kLeftPadding, bounds.x()); |   384   EXPECT_EQ(kLeftPadding, bounds.x()); | 
|   377   EXPECT_EQ(100 - kRightPadding, bounds.right()); |   385   EXPECT_EQ(100 - kRightPadding, bounds.right()); | 
|   378   EXPECT_EQ(100 - kBottomPadding - scroll_view_.GetScrollBarHeight(), |   386   EXPECT_EQ(100 - kBottomPadding - HorizontalScrollBarHeight(), bounds.y()); | 
|   379             bounds.y()); |  | 
|   380   EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); |   387   EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); | 
|   381  |   388  | 
|   382   // Both horizontal and vertical with border. |   389   // Both horizontal and vertical with border. | 
|   383   contents->SetBounds(0, 0, 300, 400); |   390   contents->SetBounds(0, 0, 300, 400); | 
|   384   scroll_view_.Layout(); |   391   scroll_view_.Layout(); | 
|   385   EXPECT_EQ( |   392   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutWidth() - kLeftPadding - | 
|   386       100 - scroll_view_.GetScrollBarWidth() - kLeftPadding - kRightPadding, |   393                 kRightPadding, | 
|   387       contents->parent()->width()); |   394             contents->parent()->width()); | 
|   388   EXPECT_EQ( |   395   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutHeight() - kTopPadding - | 
|   389       100 - scroll_view_.GetScrollBarHeight() - kTopPadding - kBottomPadding, |   396                 kBottomPadding, | 
|   390       contents->parent()->height()); |   397             contents->parent()->height()); | 
|   391   bounds = scroll_view_.horizontal_scroll_bar()->bounds(); |   398   bounds = scroll_view_.horizontal_scroll_bar()->bounds(); | 
|   392   // Check horiz. |   399   // Check horiz. | 
|   393   ASSERT_TRUE(scroll_view_.horizontal_scroll_bar() != NULL); |   400   ASSERT_TRUE(scroll_view_.horizontal_scroll_bar() != NULL); | 
|   394   EXPECT_TRUE(scroll_view_.horizontal_scroll_bar()->visible()); |   401   EXPECT_TRUE(scroll_view_.horizontal_scroll_bar()->visible()); | 
|   395   bounds = scroll_view_.horizontal_scroll_bar()->bounds(); |   402   bounds = scroll_view_.horizontal_scroll_bar()->bounds(); | 
|   396   EXPECT_EQ(kLeftPadding, bounds.x()); |   403   EXPECT_EQ(kLeftPadding, bounds.x()); | 
|   397   EXPECT_EQ(100 - kRightPadding - scroll_view_.GetScrollBarWidth(), |   404   EXPECT_EQ(100 - kRightPadding - VerticalScrollBarWidth(), bounds.right()); | 
|   398             bounds.right()); |   405   EXPECT_EQ(100 - kBottomPadding - HorizontalScrollBarHeight(), bounds.y()); | 
|   399   EXPECT_EQ(100 - kBottomPadding - scroll_view_.GetScrollBarHeight(), |  | 
|   400             bounds.y()); |  | 
|   401   EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); |   406   EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); | 
|   402   // Check vert. |   407   // Check vert. | 
|   403   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); |   408   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); | 
|   404   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); |   409   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); | 
|   405   bounds = scroll_view_.vertical_scroll_bar()->bounds(); |   410   bounds = scroll_view_.vertical_scroll_bar()->bounds(); | 
|   406   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth() - kRightPadding, bounds.x()); |   411   EXPECT_EQ(100 - VerticalScrollBarWidth() - kRightPadding, bounds.x()); | 
|   407   EXPECT_EQ(100 - kRightPadding, bounds.right()); |   412   EXPECT_EQ(100 - kRightPadding, bounds.right()); | 
|   408   EXPECT_EQ(kTopPadding, bounds.y()); |   413   EXPECT_EQ(kTopPadding, bounds.y()); | 
|   409   EXPECT_EQ(100 - kBottomPadding - scroll_view_.GetScrollBarHeight(), |   414   EXPECT_EQ(100 - kBottomPadding - HorizontalScrollBarHeight(), | 
|   410             bounds.bottom()); |   415             bounds.bottom()); | 
|   411 } |   416 } | 
|   412  |   417  | 
|   413 // Assertions around adding a header. |   418 // Assertions around adding a header. | 
|   414 TEST_F(ScrollViewTest, Header) { |   419 TEST_F(ScrollViewTest, Header) { | 
|   415   CustomView* header = new CustomView; |   420   CustomView* header = new CustomView; | 
|   416   scroll_view_.SetHeader(header); |   421   scroll_view_.SetHeader(header); | 
|   417   View* header_parent = header->parent(); |   422   View* header_parent = header->parent(); | 
|   418   View* contents = InstallContents(); |   423   View* contents = InstallContents(); | 
|   419  |   424  | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   457   scroll_view_.SetHeader(header); |   462   scroll_view_.SetHeader(header); | 
|   458   View* contents = InstallContents(); |   463   View* contents = InstallContents(); | 
|   459  |   464  | 
|   460   header->SetPreferredSize(gfx::Size(10, 20)); |   465   header->SetPreferredSize(gfx::Size(10, 20)); | 
|   461  |   466  | 
|   462   // Size the contents such that vertical scrollbar is needed. |   467   // Size the contents such that vertical scrollbar is needed. | 
|   463   contents->SetBounds(0, 0, 50, 400); |   468   contents->SetBounds(0, 0, 50, 400); | 
|   464   scroll_view_.Layout(); |   469   scroll_view_.Layout(); | 
|   465   EXPECT_EQ(0, contents->parent()->x()); |   470   EXPECT_EQ(0, contents->parent()->x()); | 
|   466   EXPECT_EQ(20, contents->parent()->y()); |   471   EXPECT_EQ(20, contents->parent()->y()); | 
|   467   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth(), |   472   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutWidth(), | 
|   468             contents->parent()->width()); |   473             contents->parent()->width()); | 
|   469   EXPECT_EQ(80, contents->parent()->height()); |   474   EXPECT_EQ(80, contents->parent()->height()); | 
|   470   EXPECT_EQ(0, header->parent()->x()); |   475   EXPECT_EQ(0, header->parent()->x()); | 
|   471   EXPECT_EQ(0, header->parent()->y()); |   476   EXPECT_EQ(0, header->parent()->y()); | 
|   472   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth(), header->parent()->width()); |   477   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutWidth(), | 
 |   478             header->parent()->width()); | 
|   473   EXPECT_EQ(20, header->parent()->height()); |   479   EXPECT_EQ(20, header->parent()->height()); | 
|   474   EXPECT_TRUE(!scroll_view_.horizontal_scroll_bar() || |   480   EXPECT_TRUE(!scroll_view_.horizontal_scroll_bar() || | 
|   475               !scroll_view_.horizontal_scroll_bar()->visible()); |   481               !scroll_view_.horizontal_scroll_bar()->visible()); | 
|   476   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); |   482   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); | 
|   477   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); |   483   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); | 
|   478   // Make sure the vertical scrollbar overlaps the header. |   484   // Make sure the vertical scrollbar overlaps the header for traditional | 
|   479   EXPECT_EQ(header->y(), scroll_view_.vertical_scroll_bar()->y()); |   485   // scrollbars and doesn't overlap the header for overlay scrollbars. | 
 |   486   const int expected_scrollbar_y = | 
 |   487       scroll_view_.vertical_scroll_bar()->OverlapsContent() | 
 |   488           ? header->bounds().bottom() | 
 |   489           : header->y(); | 
 |   490   EXPECT_EQ(expected_scrollbar_y, scroll_view_.vertical_scroll_bar()->y()); | 
|   480   EXPECT_EQ(header->y(), contents->y()); |   491   EXPECT_EQ(header->y(), contents->y()); | 
|   481  |   492  | 
|   482   // Size the contents such that horizontal scrollbar is needed. |   493   // Size the contents such that horizontal scrollbar is needed. | 
|   483   contents->SetBounds(0, 0, 400, 50); |   494   contents->SetBounds(0, 0, 400, 50); | 
|   484   scroll_view_.Layout(); |   495   scroll_view_.Layout(); | 
|   485   EXPECT_EQ(0, contents->parent()->x()); |   496   EXPECT_EQ(0, contents->parent()->x()); | 
|   486   EXPECT_EQ(20, contents->parent()->y()); |   497   EXPECT_EQ(20, contents->parent()->y()); | 
|   487   EXPECT_EQ(100, contents->parent()->width()); |   498   EXPECT_EQ(100, contents->parent()->width()); | 
|   488   EXPECT_EQ(100 - scroll_view_.GetScrollBarHeight() - 20, |   499   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutHeight() - 20, | 
|   489             contents->parent()->height()); |   500             contents->parent()->height()); | 
|   490   EXPECT_EQ(0, header->parent()->x()); |   501   EXPECT_EQ(0, header->parent()->x()); | 
|   491   EXPECT_EQ(0, header->parent()->y()); |   502   EXPECT_EQ(0, header->parent()->y()); | 
|   492   EXPECT_EQ(100, header->parent()->width()); |   503   EXPECT_EQ(100, header->parent()->width()); | 
|   493   EXPECT_EQ(20, header->parent()->height()); |   504   EXPECT_EQ(20, header->parent()->height()); | 
|   494   ASSERT_TRUE(scroll_view_.horizontal_scroll_bar() != NULL); |   505   ASSERT_TRUE(scroll_view_.horizontal_scroll_bar() != NULL); | 
|   495   EXPECT_TRUE(scroll_view_.horizontal_scroll_bar()->visible()); |   506   EXPECT_TRUE(scroll_view_.horizontal_scroll_bar()->visible()); | 
|   496   EXPECT_TRUE(!scroll_view_.vertical_scroll_bar() || |   507   EXPECT_TRUE(!scroll_view_.vertical_scroll_bar() || | 
|   497               !scroll_view_.vertical_scroll_bar()->visible()); |   508               !scroll_view_.vertical_scroll_bar()->visible()); | 
|   498  |   509  | 
|   499   // Both horizontal and vertical. |   510   // Both horizontal and vertical. | 
|   500   contents->SetBounds(0, 0, 300, 400); |   511   contents->SetBounds(0, 0, 300, 400); | 
|   501   scroll_view_.Layout(); |   512   scroll_view_.Layout(); | 
|   502   EXPECT_EQ(0, contents->parent()->x()); |   513   EXPECT_EQ(0, contents->parent()->x()); | 
|   503   EXPECT_EQ(20, contents->parent()->y()); |   514   EXPECT_EQ(20, contents->parent()->y()); | 
|   504   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth(), |   515   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutWidth(), | 
|   505             contents->parent()->width()); |   516             contents->parent()->width()); | 
|   506   EXPECT_EQ(100 - scroll_view_.GetScrollBarHeight() - 20, |   517   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutHeight() - 20, | 
|   507             contents->parent()->height()); |   518             contents->parent()->height()); | 
|   508   EXPECT_EQ(0, header->parent()->x()); |   519   EXPECT_EQ(0, header->parent()->x()); | 
|   509   EXPECT_EQ(0, header->parent()->y()); |   520   EXPECT_EQ(0, header->parent()->y()); | 
|   510   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth(), header->parent()->width()); |   521   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutWidth(), | 
 |   522             header->parent()->width()); | 
|   511   EXPECT_EQ(20, header->parent()->height()); |   523   EXPECT_EQ(20, header->parent()->height()); | 
|   512   ASSERT_TRUE(scroll_view_.horizontal_scroll_bar() != NULL); |   524   ASSERT_TRUE(scroll_view_.horizontal_scroll_bar() != NULL); | 
|   513   EXPECT_TRUE(scroll_view_.horizontal_scroll_bar()->visible()); |   525   EXPECT_TRUE(scroll_view_.horizontal_scroll_bar()->visible()); | 
|   514   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); |   526   ASSERT_TRUE(scroll_view_.vertical_scroll_bar() != NULL); | 
|   515   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); |   527   EXPECT_TRUE(scroll_view_.vertical_scroll_bar()->visible()); | 
|   516 } |   528 } | 
|   517  |   529  | 
|   518 // Verifies the header scrolls horizontally with the content. |   530 // Verifies the header scrolls horizontally with the content. | 
|   519 TEST_F(ScrollViewTest, HeaderScrollsWithContent) { |   531 TEST_F(ScrollViewTest, HeaderScrollsWithContent) { | 
|   520   ScrollViewTestApi test_api(&scroll_view_); |   532   ScrollViewTestApi test_api(&scroll_view_); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   553   scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |   565   scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); | 
|   554   scroll_view_.Layout(); |   566   scroll_view_.Layout(); | 
|   555   EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString()); |   567   EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString()); | 
|   556  |   568  | 
|   557   // Scroll to y=405 height=10, this should make the y position of the content |   569   // Scroll to y=405 height=10, this should make the y position of the content | 
|   558   // at (405 + 10) - viewport_height (scroll region bottom aligned). |   570   // at (405 + 10) - viewport_height (scroll region bottom aligned). | 
|   559   contents->ScrollRectToVisible(gfx::Rect(0, 405, 10, 10)); |   571   contents->ScrollRectToVisible(gfx::Rect(0, 405, 10, 10)); | 
|   560   const int viewport_height = test_api.contents_viewport()->height(); |   572   const int viewport_height = test_api.contents_viewport()->height(); | 
|   561  |   573  | 
|   562   // Expect there to be a horizontal scrollbar, making the viewport shorter. |   574   // Expect there to be a horizontal scrollbar, making the viewport shorter. | 
|   563   EXPECT_LT(viewport_height, 100); |   575   EXPECT_EQ(100 - scroll_view_.GetScrollBarLayoutHeight(), viewport_height); | 
|   564  |   576  | 
|   565   gfx::ScrollOffset offset = test_api.CurrentOffset(); |   577   gfx::ScrollOffset offset = test_api.CurrentOffset(); | 
|   566   EXPECT_EQ(415 - viewport_height, offset.y()); |   578   EXPECT_EQ(415 - viewport_height, offset.y()); | 
|   567  |   579  | 
|   568   // Scroll to the current y-location and 10x10; should do nothing. |   580   // Scroll to the current y-location and 10x10; should do nothing. | 
|   569   contents->ScrollRectToVisible(gfx::Rect(0, offset.y(), 10, 10)); |   581   contents->ScrollRectToVisible(gfx::Rect(0, offset.y(), 10, 10)); | 
|   570   EXPECT_EQ(415 - viewport_height, test_api.CurrentOffset().y()); |   582   EXPECT_EQ(415 - viewport_height, test_api.CurrentOffset().y()); | 
|   571 } |   583 } | 
|   572  |   584  | 
|   573 // Verifies ClipHeightTo() uses the height of the content when it is between the |   585 // Verifies ClipHeightTo() uses the height of the content when it is between the | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   611   } else { |   623   } else { | 
|   612     EXPECT_EQ(gfx::Size(kWidth, kShortContentHeight), |   624     EXPECT_EQ(gfx::Size(kWidth, kShortContentHeight), | 
|   613               scroll_view_.contents()->size()); |   625               scroll_view_.contents()->size()); | 
|   614   } |   626   } | 
|   615   EXPECT_EQ(gfx::Size(kWidth, kMinHeight), scroll_view_.size()); |   627   EXPECT_EQ(gfx::Size(kWidth, kMinHeight), scroll_view_.size()); | 
|   616 } |   628 } | 
|   617  |   629  | 
|   618 // Verifies ClipHeightTo() uses the maximum height when the content is longer |   630 // Verifies ClipHeightTo() uses the maximum height when the content is longer | 
|   619 // thamn the maximum height value. |   631 // thamn the maximum height value. | 
|   620 TEST_F(ScrollViewTest, ClipHeightToTallContentHeight) { |   632 TEST_F(ScrollViewTest, ClipHeightToTallContentHeight) { | 
|   621   // Use a scrollbar that is disabled by default, so the width of the content is |  | 
|   622   // not affected. |  | 
|   623   scroll_view_.SetVerticalScrollBar(new views::OverlayScrollBar(false)); |  | 
|   624  |  | 
|   625   scroll_view_.ClipHeightTo(kMinHeight, kMaxHeight); |   633   scroll_view_.ClipHeightTo(kMinHeight, kMaxHeight); | 
|   626  |   634  | 
|   627   const int kTallContentHeight = 1000; |   635   const int kTallContentHeight = 1000; | 
|   628   scroll_view_.SetContents( |   636   scroll_view_.SetContents( | 
|   629       new views::StaticSizedView(gfx::Size(kWidth, kTallContentHeight))); |   637       new views::StaticSizedView(gfx::Size(kWidth, kTallContentHeight))); | 
|   630  |   638  | 
|   631   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view_.GetPreferredSize()); |   639   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view_.GetPreferredSize()); | 
|   632  |   640  | 
|   633   scroll_view_.SizeToPreferredSize(); |   641   scroll_view_.SizeToPreferredSize(); | 
|   634   scroll_view_.Layout(); |   642   scroll_view_.Layout(); | 
|   635  |   643  | 
|   636   EXPECT_EQ(gfx::Size(kWidth, kTallContentHeight), |   644   // The width may be less than kWidth if the scroll bar takes up some width. | 
|   637             scroll_view_.contents()->size()); |   645   EXPECT_GE(kWidth, scroll_view_.contents()->width()); | 
 |   646   EXPECT_EQ(kTallContentHeight, scroll_view_.contents()->height()); | 
|   638   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view_.size()); |   647   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view_.size()); | 
|   639 } |   648 } | 
|   640  |   649  | 
|   641 // Verifies that when ClipHeightTo() produces a scrollbar, it reduces the width |   650 // Verifies that when ClipHeightTo() produces a scrollbar, it reduces the width | 
|   642 // of the inner content of the ScrollView. |   651 // of the inner content of the ScrollView. | 
|   643 TEST_F(ScrollViewTest, ClipHeightToScrollbarUsesWidth) { |   652 TEST_F(ScrollViewTest, ClipHeightToScrollbarUsesWidth) { | 
|   644   scroll_view_.ClipHeightTo(kMinHeight, kMaxHeight); |   653   scroll_view_.ClipHeightTo(kMinHeight, kMaxHeight); | 
|   645  |   654  | 
|   646   // Create a view that will be much taller than it is wide. |   655   // Create a view that will be much taller than it is wide. | 
|   647   scroll_view_.SetContents(new views::ProportionallySizedView(1000)); |   656   scroll_view_.SetContents(new views::ProportionallySizedView(1000)); | 
|   648  |   657  | 
|   649   // Without any width, it will default to 0,0 but be overridden by min height. |   658   // Without any width, it will default to 0,0 but be overridden by min height. | 
|   650   scroll_view_.SizeToPreferredSize(); |   659   scroll_view_.SizeToPreferredSize(); | 
|   651   EXPECT_EQ(gfx::Size(0, kMinHeight), scroll_view_.GetPreferredSize()); |   660   EXPECT_EQ(gfx::Size(0, kMinHeight), scroll_view_.GetPreferredSize()); | 
|   652  |   661  | 
|   653   gfx::Size new_size(kWidth, scroll_view_.GetHeightForWidth(kWidth)); |   662   gfx::Size new_size(kWidth, scroll_view_.GetHeightForWidth(kWidth)); | 
|   654   scroll_view_.SetSize(new_size); |   663   scroll_view_.SetSize(new_size); | 
|   655   scroll_view_.Layout(); |   664   scroll_view_.Layout(); | 
|   656  |   665  | 
|   657   int scroll_bar_width = scroll_view_.GetScrollBarWidth(); |   666   int expected_width = kWidth - scroll_view_.GetScrollBarLayoutWidth(); | 
|   658   int expected_width = kWidth - scroll_bar_width; |  | 
|   659   EXPECT_EQ(scroll_view_.contents()->size().width(), expected_width); |   667   EXPECT_EQ(scroll_view_.contents()->size().width(), expected_width); | 
|   660   EXPECT_EQ(scroll_view_.contents()->size().height(), 1000 * expected_width); |   668   EXPECT_EQ(scroll_view_.contents()->size().height(), 1000 * expected_width); | 
|   661   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view_.size()); |   669   EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view_.size()); | 
|   662 } |   670 } | 
|   663  |   671  | 
|   664 TEST_F(ScrollViewTest, CornerViewVisibility) { |   672 TEST_F(ScrollViewTest, CornerViewVisibility) { | 
|   665   View* contents = InstallContents(); |   673   View* contents = InstallContents(); | 
|   666   View* corner_view = ScrollViewTestApi(&scroll_view_).corner_view(); |   674   View* corner_view = ScrollViewTestApi(&scroll_view_).corner_view(); | 
|   667  |   675  | 
|   668   // Corner view should be visible when both scrollbars are visible. |  | 
|   669   contents->SetBounds(0, 0, 200, 200); |   676   contents->SetBounds(0, 0, 200, 200); | 
|   670   scroll_view_.Layout(); |   677   scroll_view_.Layout(); | 
 |   678  | 
 |   679   // Corner view should not exist if using overlay scrollbars. | 
 |   680   if (scroll_view_.vertical_scroll_bar()->OverlapsContent()) { | 
 |   681     EXPECT_FALSE(corner_view->parent()); | 
 |   682     return; | 
 |   683   } | 
 |   684  | 
 |   685   // Corner view should be visible when both scrollbars are visible. | 
|   671   EXPECT_EQ(&scroll_view_, corner_view->parent()); |   686   EXPECT_EQ(&scroll_view_, corner_view->parent()); | 
|   672   EXPECT_TRUE(corner_view->visible()); |   687   EXPECT_TRUE(corner_view->visible()); | 
|   673  |   688  | 
|   674   // Corner view should be aligned to the scrollbars. |   689   // Corner view should be aligned to the scrollbars. | 
|   675   EXPECT_EQ(scroll_view_.vertical_scroll_bar()->x(), corner_view->x()); |   690   EXPECT_EQ(scroll_view_.vertical_scroll_bar()->x(), corner_view->x()); | 
|   676   EXPECT_EQ(scroll_view_.horizontal_scroll_bar()->y(), corner_view->y()); |   691   EXPECT_EQ(scroll_view_.horizontal_scroll_bar()->y(), corner_view->y()); | 
|   677   EXPECT_EQ(scroll_view_.GetScrollBarWidth(), corner_view->width()); |   692   EXPECT_EQ(scroll_view_.GetScrollBarLayoutWidth(), corner_view->width()); | 
|   678   EXPECT_EQ(scroll_view_.GetScrollBarHeight(), corner_view->height()); |   693   EXPECT_EQ(scroll_view_.GetScrollBarLayoutHeight(), corner_view->height()); | 
|   679  |   694  | 
|   680   // Corner view should be removed when only the vertical scrollbar is visible. |   695   // Corner view should be removed when only the vertical scrollbar is visible. | 
|   681   contents->SetBounds(0, 0, 50, 200); |   696   contents->SetBounds(0, 0, 50, 200); | 
|   682   scroll_view_.Layout(); |   697   scroll_view_.Layout(); | 
|   683   EXPECT_FALSE(corner_view->parent()); |   698   EXPECT_FALSE(corner_view->parent()); | 
|   684  |   699  | 
|   685   // ... or when only the horizontal scrollbar is visible. |   700   // ... or when only the horizontal scrollbar is visible. | 
|   686   contents->SetBounds(0, 0, 200, 50); |   701   contents->SetBounds(0, 0, 200, 50); | 
|   687   scroll_view_.Layout(); |   702   scroll_view_.Layout(); | 
|   688   EXPECT_FALSE(corner_view->parent()); |   703   EXPECT_FALSE(corner_view->parent()); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|   705 TEST_F(ScrollViewTest, CocoaOverlayScrollBars) { |   720 TEST_F(ScrollViewTest, CocoaOverlayScrollBars) { | 
|   706   SetOverlayScrollersEnabled(true); |   721   SetOverlayScrollersEnabled(true); | 
|   707   View* contents = InstallContents(); |   722   View* contents = InstallContents(); | 
|   708  |   723  | 
|   709   // Size the contents such that vertical scrollbar is needed. |   724   // Size the contents such that vertical scrollbar is needed. | 
|   710   // Since it is overlaid, the ViewPort size should match the ScrollView. |   725   // Since it is overlaid, the ViewPort size should match the ScrollView. | 
|   711   contents->SetBounds(0, 0, 50, 400); |   726   contents->SetBounds(0, 0, 50, 400); | 
|   712   scroll_view_.Layout(); |   727   scroll_view_.Layout(); | 
|   713   EXPECT_EQ(100, contents->parent()->width()); |   728   EXPECT_EQ(100, contents->parent()->width()); | 
|   714   EXPECT_EQ(100, contents->parent()->height()); |   729   EXPECT_EQ(100, contents->parent()->height()); | 
|   715   EXPECT_EQ(0, scroll_view_.GetScrollBarWidth()); |   730   EXPECT_EQ(0, scroll_view_.GetScrollBarLayoutWidth()); | 
|   716   CheckScrollbarVisibility(scroll_view_, VERTICAL, true); |   731   CheckScrollbarVisibility(scroll_view_, VERTICAL, true); | 
|   717   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, false); |   732   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, false); | 
|   718  |   733  | 
|   719   // Size the contents such that horizontal scrollbar is needed. |   734   // Size the contents such that horizontal scrollbar is needed. | 
|   720   contents->SetBounds(0, 0, 400, 50); |   735   contents->SetBounds(0, 0, 400, 50); | 
|   721   scroll_view_.Layout(); |   736   scroll_view_.Layout(); | 
|   722   EXPECT_EQ(100, contents->parent()->width()); |   737   EXPECT_EQ(100, contents->parent()->width()); | 
|   723   EXPECT_EQ(100, contents->parent()->height()); |   738   EXPECT_EQ(100, contents->parent()->height()); | 
|   724   EXPECT_EQ(0, scroll_view_.GetScrollBarHeight()); |   739   EXPECT_EQ(0, scroll_view_.GetScrollBarLayoutHeight()); | 
|   725   CheckScrollbarVisibility(scroll_view_, VERTICAL, false); |   740   CheckScrollbarVisibility(scroll_view_, VERTICAL, false); | 
|   726   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, true); |   741   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, true); | 
|   727  |   742  | 
|   728   // Both horizontal and vertical scrollbars. |   743   // Both horizontal and vertical scrollbars. | 
|   729   contents->SetBounds(0, 0, 300, 400); |   744   contents->SetBounds(0, 0, 300, 400); | 
|   730   scroll_view_.Layout(); |   745   scroll_view_.Layout(); | 
|   731   EXPECT_EQ(100, contents->parent()->width()); |   746   EXPECT_EQ(100, contents->parent()->width()); | 
|   732   EXPECT_EQ(100, contents->parent()->height()); |   747   EXPECT_EQ(100, contents->parent()->height()); | 
|   733   EXPECT_EQ(0, scroll_view_.GetScrollBarWidth()); |   748   EXPECT_EQ(0, scroll_view_.GetScrollBarLayoutWidth()); | 
|   734   EXPECT_EQ(0, scroll_view_.GetScrollBarHeight()); |   749   EXPECT_EQ(0, scroll_view_.GetScrollBarLayoutHeight()); | 
|   735   CheckScrollbarVisibility(scroll_view_, VERTICAL, true); |   750   CheckScrollbarVisibility(scroll_view_, VERTICAL, true); | 
|   736   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, true); |   751   CheckScrollbarVisibility(scroll_view_, HORIZONTAL, true); | 
|   737  |   752  | 
|   738   // Make sure the horizontal and vertical scrollbars don't overlap each other. |   753   // Make sure the horizontal and vertical scrollbars don't overlap each other. | 
|   739   gfx::Rect vert_bounds = scroll_view_.vertical_scroll_bar()->bounds(); |   754   gfx::Rect vert_bounds = scroll_view_.vertical_scroll_bar()->bounds(); | 
|   740   gfx::Rect horiz_bounds = scroll_view_.horizontal_scroll_bar()->bounds(); |   755   gfx::Rect horiz_bounds = scroll_view_.horizontal_scroll_bar()->bounds(); | 
|   741   EXPECT_EQ(vert_bounds.x(), horiz_bounds.right()); |   756   EXPECT_EQ(vert_bounds.x(), horiz_bounds.right()); | 
|   742   EXPECT_EQ(horiz_bounds.y(), vert_bounds.bottom()); |   757   EXPECT_EQ(horiz_bounds.y(), vert_bounds.bottom()); | 
|   743  |   758  | 
|   744   // Switch to the non-overlay style and check that the ViewPort is now sized |   759   // Switch to the non-overlay style and check that the ViewPort is now sized | 
|   745   // to be smaller, and ScrollbarWidth and ScrollbarHeight are non-zero. |   760   // to be smaller, and ScrollbarWidth and ScrollbarHeight are non-zero. | 
|   746   SetOverlayScrollersEnabled(false); |   761   SetOverlayScrollersEnabled(false); | 
|   747   EXPECT_EQ(100 - scroll_view_.GetScrollBarWidth(), |   762   EXPECT_EQ(100 - VerticalScrollBarWidth(), contents->parent()->width()); | 
|   748             contents->parent()->width()); |   763   EXPECT_EQ(100 - HorizontalScrollBarHeight(), contents->parent()->height()); | 
|   749   EXPECT_EQ(100 - scroll_view_.GetScrollBarHeight(), |   764   EXPECT_NE(0, VerticalScrollBarWidth()); | 
|   750             contents->parent()->height()); |   765   EXPECT_NE(0, HorizontalScrollBarHeight()); | 
|   751   EXPECT_NE(0, scroll_view_.GetScrollBarWidth()); |  | 
|   752   EXPECT_NE(0, scroll_view_.GetScrollBarHeight()); |  | 
|   753 } |   766 } | 
|   754  |   767  | 
|   755 // Test overlay scrollbar behavior when just resting fingers on the trackpad. |   768 // Test overlay scrollbar behavior when just resting fingers on the trackpad. | 
|   756 TEST_F(WidgetScrollViewTest, ScrollersOnRest) { |   769 TEST_F(WidgetScrollViewTest, ScrollersOnRest) { | 
|   757   // Allow expectations to distinguish between fade outs and immediate changes. |   770   // Allow expectations to distinguish between fade outs and immediate changes. | 
|   758   ui::ScopedAnimationDurationScaleMode really_animate( |   771   ui::ScopedAnimationDurationScaleMode really_animate( | 
|   759       ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |   772       ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 
|   760  |   773  | 
|   761   const float kMaxOpacity = 0.8f;  // Constant from cocoa_scroll_bar.mm. |   774   const float kMaxOpacity = 0.8f;  // Constant from cocoa_scroll_bar.mm. | 
|   762  |   775  | 
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1018   // Scroll via ScrollView API. Should be reflected on the impl side. |  1031   // Scroll via ScrollView API. Should be reflected on the impl side. | 
|  1019   offset.set_y(kDefaultHeight * 4); |  1032   offset.set_y(kDefaultHeight * 4); | 
|  1020   scroll_view->contents()->ScrollRectToVisible(offset); |  1033   scroll_view->contents()->ScrollRectToVisible(offset); | 
|  1021   EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); |  1034   EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); | 
|  1022  |  1035  | 
|  1023   EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); |  1036   EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); | 
|  1024   EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); |  1037   EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); | 
|  1025 } |  1038 } | 
|  1026  |  1039  | 
|  1027 }  // namespace views |  1040 }  // namespace views | 
| OLD | NEW |