Commit 4c40d5ad authored by estade's avatar estade Committed by Commit bot

Remove NativeScrollBar*.

NativeScrollBar used to wrap NativeScrollBarViews, but it was almost
entirely a pass-through shim. Thus, now we just have one layer of views
scrollbars called ScrollBarViews.

BUG=662605

Review-Url: https://codereview.chromium.org/2480763005
Cr-Commit-Position: refs/heads/master@{#430316}
parent 1d6f9210
......@@ -34,7 +34,7 @@
#include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/controls/scrollbar/native_scroll_bar.h"
#include "ui/views/controls/scrollbar/scroll_bar_views.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"
......@@ -936,9 +936,10 @@ int StatusBubbleViews::GetStandardStatusBubbleWidth() {
int StatusBubbleViews::GetMaxStatusBubbleWidth() {
const ui::NativeTheme* theme = base_view_->GetNativeTheme();
return static_cast<int>(std::max(0, base_view_->bounds().width() -
(kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1 -
views::NativeScrollBar::GetVerticalScrollBarWidth(theme)));
return static_cast<int>(
std::max(0, base_view_->bounds().width() - (kShadowThickness * 2) -
kTextPositionX - kTextHorizPadding - 1 -
views::ScrollBarViews::GetVerticalScrollBarWidth(theme)));
}
void StatusBubbleViews::SetBubbleWidth(int width) {
......
......@@ -208,15 +208,12 @@ component("views") {
"controls/scrollbar/base_scroll_bar_thumb.h",
"controls/scrollbar/cocoa_scroll_bar.h",
"controls/scrollbar/cocoa_scroll_bar.mm",
"controls/scrollbar/native_scroll_bar.cc",
"controls/scrollbar/native_scroll_bar.h",
"controls/scrollbar/native_scroll_bar_views.cc",
"controls/scrollbar/native_scroll_bar_views.h",
"controls/scrollbar/native_scroll_bar_wrapper.h",
"controls/scrollbar/overlay_scroll_bar.cc",
"controls/scrollbar/overlay_scroll_bar.h",
"controls/scrollbar/scroll_bar.cc",
"controls/scrollbar/scroll_bar.h",
"controls/scrollbar/scroll_bar_views.cc",
"controls/scrollbar/scroll_bar_views.h",
"controls/separator.cc",
"controls/separator.h",
"controls/slide_out_view.cc",
......
......@@ -11,9 +11,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/border.h"
#include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h"
#include "ui/views/controls/scrollbar/native_scroll_bar.h"
#include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
#include "ui/views/controls/scrollbar/scroll_bar_views.h"
#include "ui/views/test/test_views.h"
#include "ui/views/test/widget_test.h"
......@@ -34,10 +33,6 @@ class ScrollViewTestApi {
BaseScrollBar* GetBaseScrollBar(ScrollBarOrientation orientation) {
ScrollBar* scroll_bar = orientation == VERTICAL ? scroll_view_->vert_sb_
: scroll_view_->horiz_sb_;
if (scroll_bar->GetClassName() == NativeScrollBar::kViewClassName) {
return static_cast<NativeScrollBarViews*>(
static_cast<NativeScrollBar*>(scroll_bar)->native_wrapper_);
}
return static_cast<BaseScrollBar*>(scroll_bar);
}
......
......@@ -119,8 +119,8 @@ class VIEWS_EXPORT BaseScrollBar : public ScrollBar,
private:
friend class test::ScrollViewTestApi;
FRIEND_TEST_ALL_PREFIXES(NativeScrollBarTest, ScrollBarFitsToBottom);
FRIEND_TEST_ALL_PREFIXES(NativeScrollBarTest, ThumbFullLengthOfTrack);
FRIEND_TEST_ALL_PREFIXES(ScrollBarViewsTest, ScrollBarFitsToBottom);
FRIEND_TEST_ALL_PREFIXES(ScrollBarViewsTest, ThumbFullLengthOfTrack);
int GetThumbSizeForTest();
// Changes to 'pushed' state and starts a timer to scroll repeatedly.
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/controls/scrollbar/native_scroll_bar.h"
#include <algorithm>
#include <string>
#include "base/message_loop/message_loop.h"
#include "ui/events/event.h"
#include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
#include "ui/views/controls/scrollbar/native_scroll_bar_wrapper.h"
#include "ui/views/widget/widget.h"
namespace views {
// static
const char NativeScrollBar::kViewClassName[] = "NativeScrollBar";
////////////////////////////////////////////////////////////////////////////////
// NativeScrollBar, public:
NativeScrollBar::NativeScrollBar(bool is_horizontal)
: ScrollBar(is_horizontal),
native_wrapper_(NULL) {
}
NativeScrollBar::~NativeScrollBar() {
}
// static
int NativeScrollBar::GetHorizontalScrollBarHeight(
const ui::NativeTheme* theme) {
return NativeScrollBarWrapper::GetHorizontalScrollBarHeight(theme);
}
// static
int NativeScrollBar::GetVerticalScrollBarWidth(
const ui::NativeTheme* theme) {
return NativeScrollBarWrapper::GetVerticalScrollBarWidth(theme);
}
////////////////////////////////////////////////////////////////////////////////
// NativeScrollBar, View overrides:
gfx::Size NativeScrollBar::GetPreferredSize() const {
if (native_wrapper_)
return native_wrapper_->GetView()->GetPreferredSize();
return gfx::Size();
}
void NativeScrollBar::Layout() {
if (native_wrapper_) {
native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
native_wrapper_->GetView()->Layout();
}
}
void NativeScrollBar::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
if (details.is_add && !native_wrapper_ && GetWidget()) {
native_wrapper_ = NativeScrollBarWrapper::CreateWrapper(this);
AddChildView(native_wrapper_->GetView());
}
}
const char* NativeScrollBar::GetClassName() const {
return kViewClassName;
}
// Overridden from View for keyboard UI.
bool NativeScrollBar::OnKeyPressed(const ui::KeyEvent& event) {
if (!native_wrapper_)
return false;
return native_wrapper_->GetView()->OnKeyPressed(event);
}
void NativeScrollBar::OnGestureEvent(ui::GestureEvent* event) {
if (!native_wrapper_)
return;
native_wrapper_->GetView()->OnGestureEvent(event);
}
bool NativeScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) {
if (!native_wrapper_)
return false;
return native_wrapper_->GetView()->OnMouseWheel(event);
}
////////////////////////////////////////////////////////////////////////////////
// NativeScrollBar, ScrollBar overrides:
void NativeScrollBar::Update(int viewport_size,
int content_size,
int current_pos) {
ScrollBar::Update(viewport_size, content_size, current_pos);
if (native_wrapper_)
native_wrapper_->Update(viewport_size, content_size, current_pos);
}
int NativeScrollBar::GetLayoutSize() const {
return IsHorizontal() ?
GetHorizontalScrollBarHeight(GetNativeTheme()) :
GetVerticalScrollBarWidth(GetNativeTheme());
}
int NativeScrollBar::GetPosition() const {
if (!native_wrapper_)
return 0;
return native_wrapper_->GetPosition();
}
} // namespace views
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_H_
#define UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_H_
#include <string>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "ui/views/controls/scrollbar/scroll_bar.h"
#include "ui/views/view.h"
namespace ui {
class NativeTheme;
}
namespace views {
namespace test {
class ScrollViewTestApi;
}
class NativeScrollBarWrapper;
// The NativeScrollBar class is a scrollbar that uses platform's
// native control.
class VIEWS_EXPORT NativeScrollBar : public ScrollBar {
public:
// The scroll-bar's class name.
static const char kViewClassName[];
// Create new scrollbar, either horizontal or vertical.
explicit NativeScrollBar(bool is_horiz);
~NativeScrollBar() override;
// Return the system sizes.
static int GetHorizontalScrollBarHeight(const ui::NativeTheme* theme);
static int GetVerticalScrollBarWidth(const ui::NativeTheme* theme);
private:
friend class NativeScrollBarTest;
friend class test::ScrollViewTestApi;
FRIEND_TEST_ALL_PREFIXES(NativeScrollBarTest, Scrolling);
// Overridden from View.
gfx::Size GetPreferredSize() const override;
void Layout() override;
void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) override;
const char* GetClassName() const override;
// Overrideen from View for keyboard UI purpose.
bool OnKeyPressed(const ui::KeyEvent& event) override;
bool OnMouseWheel(const ui::MouseWheelEvent& e) override;
// Overridden from ui::EventHandler.
void OnGestureEvent(ui::GestureEvent* event) override;
// Overridden from ScrollBar.
void Update(int viewport_size, int content_size, int current_pos) override;
int GetPosition() const override;
int GetLayoutSize() const override;
// init border
NativeScrollBarWrapper* native_wrapper_;
DISALLOW_COPY_AND_ASSIGN(NativeScrollBar);
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_WRAPPER_H_
#define UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_WRAPPER_H_
#include "ui/views/views_export.h"
namespace ui {
class NativeTheme;
}
namespace views {
class NativeScrollBar;
class View;
// A specialization of NativeControlWrapper that hosts a platform-native
// scroll bar.
class VIEWS_EXPORT NativeScrollBarWrapper {
public:
virtual ~NativeScrollBarWrapper() {}
// Updates the scroll bar appearance given a viewport size, content size and
// current position.
virtual void Update(int viewport_size, int content_size, int current_pos) = 0;
// Retrieves the views::View that hosts the native control.
virtual View* GetView() = 0;
// Returns the position of the scrollbar.
virtual int GetPosition() const = 0;
// Creates an appropriate NativeScrollBarWrapper for the platform.
static NativeScrollBarWrapper* CreateWrapper(NativeScrollBar* button);
// Returns the system sizes of vertical/horizontal scroll bars.
static int GetVerticalScrollBarWidth(const ui::NativeTheme* theme);
static int GetHorizontalScrollBarHeight(const ui::NativeTheme* theme);
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_WRAPPER_H_
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_VIEWS_H_
#define UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_VIEWS_H_
#ifndef UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_VIEWS_H_
#define UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_VIEWS_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
......@@ -11,7 +11,6 @@
#include "ui/native_theme/native_theme.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/scrollbar/base_scroll_bar.h"
#include "ui/views/controls/scrollbar/native_scroll_bar_wrapper.h"
#include "ui/views/view.h"
namespace gfx {
......@@ -20,20 +19,19 @@ class Canvas;
namespace views {
class NativeScrollBar;
// Views implementation for the scrollbar.
class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar,
public ButtonListener,
public NativeScrollBarWrapper {
class VIEWS_EXPORT ScrollBarViews : public BaseScrollBar,
public ButtonListener {
public:
static const char kViewClassName[];
// Creates new scrollbar, either horizontal or vertical.
explicit NativeScrollBarViews(NativeScrollBar* native_scroll_bar);
~NativeScrollBarViews() override;
explicit ScrollBarViews(bool horizontal);
~ScrollBarViews() override;
private:
static int GetVerticalScrollBarWidth(const ui::NativeTheme* theme);
protected:
// View overrides:
void Layout() override;
void OnPaint(gfx::Canvas* canvas) override;
......@@ -43,24 +41,15 @@ class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar,
// ScrollBar overrides:
int GetLayoutSize() const override;
// BaseScrollBar overrides:
void ScrollToPosition(int position) override;
int GetScrollIncrement(bool is_page, bool is_positive) override;
// BaseButton::ButtonListener overrides:
void ButtonPressed(Button* sender, const ui::Event& event) override;
// NativeScrollBarWrapper overrides:
int GetPosition() const override;
View* GetView() override;
void Update(int viewport_size, int content_size, int current_pos) override;
// Returns the area for the track. This is the area of the scrollbar minus
// the size of the arrow buttons.
gfx::Rect GetTrackBounds() const override;
// The NativeScrollBar we are bound to.
NativeScrollBar* native_scroll_bar_;
private:
static int GetHorizontalScrollBarHeight(const ui::NativeTheme* theme);
// The scroll bar buttons (Up/Down, Left/Right).
Button* prev_button_;
......@@ -70,9 +59,9 @@ class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar,
ui::NativeTheme::Part part_;
ui::NativeTheme::State state_;
DISALLOW_COPY_AND_ASSIGN(NativeScrollBarViews);
DISALLOW_COPY_AND_ASSIGN(ScrollBarViews);
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_VIEWS_H_
#endif // UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_VIEWS_H_
......@@ -3,9 +3,8 @@
// found in the LICENSE file.
#include "build/build_config.h"
#include "ui/views/controls/scrollbar/native_scroll_bar.h"
#include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
#include "ui/views/controls/scrollbar/scroll_bar.h"
#include "ui/views/controls/scrollbar/scroll_bar_views.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
......@@ -46,31 +45,26 @@ class TestScrollBarController : public views::ScrollBarController {
namespace views {
class NativeScrollBarTest : public ViewsTestBase {
class ScrollBarViewsTest : public ViewsTestBase {
public:
NativeScrollBarTest() : widget_(NULL), scrollbar_(NULL) {}
ScrollBarViewsTest() : widget_(nullptr), scrollbar_(nullptr) {}
void SetUp() override {
ViewsTestBase::SetUp();
controller_.reset(new TestScrollBarController());
ASSERT_FALSE(scrollbar_);
native_scrollbar_ = new NativeScrollBar(true);
native_scrollbar_->SetBounds(0, 0, 100, 100);
native_scrollbar_->set_controller(controller_.get());
widget_ = new Widget;
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.bounds = gfx::Rect(0, 0, 100, 100);
widget_->Init(params);
View* container = new View();
widget_->SetContentsView(container);
container->AddChildView(native_scrollbar_);
scrollbar_ =
static_cast<NativeScrollBarViews*>(native_scrollbar_->native_wrapper_);
scrollbar_ = new ScrollBarViews(true);
scrollbar_->SetBounds(0, 0, 100, 100);
scrollbar_->Update(100, 1000, 0);
scrollbar_->set_controller(controller_.get());
container->AddChildView(scrollbar_);
track_size_ = scrollbar_->GetTrackBounds().width();
}
......@@ -83,9 +77,6 @@ class NativeScrollBarTest : public ViewsTestBase {
protected:
Widget* widget_;
// This is the native scrollbar the Views one wraps around.
NativeScrollBar* native_scrollbar_;
// This is the Views scrollbar.
BaseScrollBar* scrollbar_;
......@@ -106,7 +97,7 @@ class NativeScrollBarTest : public ViewsTestBase {
#define MAYBE_ScrollBarFitsToBottom ScrollBarFitsToBottom
#endif
TEST_F(NativeScrollBarTest, MAYBE_Scrolling) {
TEST_F(ScrollBarViewsTest, MAYBE_Scrolling) {
EXPECT_EQ(0, scrollbar_->GetPosition());
EXPECT_EQ(900, scrollbar_->GetMaxPosition());
EXPECT_EQ(0, scrollbar_->GetMinPosition());
......@@ -114,7 +105,7 @@ TEST_F(NativeScrollBarTest, MAYBE_Scrolling) {
// Scroll to middle.
scrollbar_->ScrollToThumbPosition(track_size_ / 2, true);
EXPECT_EQ(450, controller_->last_position);
EXPECT_EQ(native_scrollbar_, controller_->last_source);
EXPECT_EQ(scrollbar_, controller_->last_source);
// Scroll to the end.
scrollbar_->ScrollToThumbPosition(track_size_, true);
......@@ -144,7 +135,7 @@ TEST_F(NativeScrollBarTest, MAYBE_Scrolling) {
EXPECT_EQ(0, controller_->last_position);
}
TEST_F(NativeScrollBarTest, MAYBE_ScrollBarFitsToBottom) {
TEST_F(ScrollBarViewsTest, MAYBE_ScrollBarFitsToBottom) {
scrollbar_->Update(100, 1999, 0);
EXPECT_EQ(0, scrollbar_->GetPosition());
EXPECT_EQ(1899, scrollbar_->GetMaxPosition());
......@@ -164,7 +155,7 @@ TEST_F(NativeScrollBarTest, MAYBE_ScrollBarFitsToBottom) {
scrollbar_->GetPosition());
}
TEST_F(NativeScrollBarTest, ScrollToEndAfterShrinkAndExpand) {
TEST_F(ScrollBarViewsTest, ScrollToEndAfterShrinkAndExpand) {
// Scroll to the end of the content.
scrollbar_->Update(100, 1001, 0);
EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1));
......@@ -175,7 +166,7 @@ TEST_F(NativeScrollBarTest, ScrollToEndAfterShrinkAndExpand) {
EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1));
}
TEST_F(NativeScrollBarTest, ThumbFullLengthOfTrack) {
TEST_F(ScrollBarViewsTest, ThumbFullLengthOfTrack) {
// Shrink content so that it fits within the viewport.
scrollbar_->Update(100, 10, 0);
EXPECT_EQ(scrollbar_->GetTrackBounds().width(),
......
......@@ -15,7 +15,7 @@
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h"
#include "ui/views/controls/focusable_border.h"
#include "ui/views/controls/scrollbar/native_scroll_bar.h"
#include "ui/views/controls/scrollbar/scroll_bar_views.h"
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#define DESKTOP_LINUX
......@@ -55,7 +55,7 @@ gfx::ImageSkia PlatformStyle::CreateComboboxArrow(bool is_enabled,
// static
std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) {
return base::MakeUnique<NativeScrollBar>(is_horizontal);
return base::MakeUnique<ScrollBarViews>(is_horizontal);
}
// static
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment