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 @@ ...@@ -34,7 +34,7 @@
#include "ui/gfx/text_elider.h" #include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h" #include "ui/gfx/text_utils.h"
#include "ui/native_theme/native_theme.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/root_view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -936,9 +936,10 @@ int StatusBubbleViews::GetStandardStatusBubbleWidth() { ...@@ -936,9 +936,10 @@ int StatusBubbleViews::GetStandardStatusBubbleWidth() {
int StatusBubbleViews::GetMaxStatusBubbleWidth() { int StatusBubbleViews::GetMaxStatusBubbleWidth() {
const ui::NativeTheme* theme = base_view_->GetNativeTheme(); const ui::NativeTheme* theme = base_view_->GetNativeTheme();
return static_cast<int>(std::max(0, base_view_->bounds().width() - return static_cast<int>(
(kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1 - std::max(0, base_view_->bounds().width() - (kShadowThickness * 2) -
views::NativeScrollBar::GetVerticalScrollBarWidth(theme))); kTextPositionX - kTextHorizPadding - 1 -
views::ScrollBarViews::GetVerticalScrollBarWidth(theme)));
} }
void StatusBubbleViews::SetBubbleWidth(int width) { void StatusBubbleViews::SetBubbleWidth(int width) {
......
...@@ -208,15 +208,12 @@ component("views") { ...@@ -208,15 +208,12 @@ component("views") {
"controls/scrollbar/base_scroll_bar_thumb.h", "controls/scrollbar/base_scroll_bar_thumb.h",
"controls/scrollbar/cocoa_scroll_bar.h", "controls/scrollbar/cocoa_scroll_bar.h",
"controls/scrollbar/cocoa_scroll_bar.mm", "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.cc",
"controls/scrollbar/overlay_scroll_bar.h", "controls/scrollbar/overlay_scroll_bar.h",
"controls/scrollbar/scroll_bar.cc", "controls/scrollbar/scroll_bar.cc",
"controls/scrollbar/scroll_bar.h", "controls/scrollbar/scroll_bar.h",
"controls/scrollbar/scroll_bar_views.cc",
"controls/scrollbar/scroll_bar_views.h",
"controls/separator.cc", "controls/separator.cc",
"controls/separator.h", "controls/separator.h",
"controls/slide_out_view.cc", "controls/slide_out_view.cc",
......
...@@ -11,9 +11,8 @@ ...@@ -11,9 +11,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/scrollbar/base_scroll_bar_thumb.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/overlay_scroll_bar.h"
#include "ui/views/controls/scrollbar/scroll_bar_views.h"
#include "ui/views/test/test_views.h" #include "ui/views/test/test_views.h"
#include "ui/views/test/widget_test.h" #include "ui/views/test/widget_test.h"
...@@ -34,10 +33,6 @@ class ScrollViewTestApi { ...@@ -34,10 +33,6 @@ class ScrollViewTestApi {
BaseScrollBar* GetBaseScrollBar(ScrollBarOrientation orientation) { BaseScrollBar* GetBaseScrollBar(ScrollBarOrientation orientation) {
ScrollBar* scroll_bar = orientation == VERTICAL ? scroll_view_->vert_sb_ ScrollBar* scroll_bar = orientation == VERTICAL ? scroll_view_->vert_sb_
: scroll_view_->horiz_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); return static_cast<BaseScrollBar*>(scroll_bar);
} }
......
...@@ -119,8 +119,8 @@ class VIEWS_EXPORT BaseScrollBar : public ScrollBar, ...@@ -119,8 +119,8 @@ class VIEWS_EXPORT BaseScrollBar : public ScrollBar,
private: private:
friend class test::ScrollViewTestApi; friend class test::ScrollViewTestApi;
FRIEND_TEST_ALL_PREFIXES(NativeScrollBarTest, ScrollBarFitsToBottom); FRIEND_TEST_ALL_PREFIXES(ScrollBarViewsTest, ScrollBarFitsToBottom);
FRIEND_TEST_ALL_PREFIXES(NativeScrollBarTest, ThumbFullLengthOfTrack); FRIEND_TEST_ALL_PREFIXES(ScrollBarViewsTest, ThumbFullLengthOfTrack);
int GetThumbSizeForTest(); int GetThumbSizeForTest();
// Changes to 'pushed' state and starts a timer to scroll repeatedly. // 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,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/views/controls/scrollbar/native_scroll_bar_views.h" #include "ui/views/controls/scrollbar/scroll_bar_views.h"
#include "base/logging.h" #include "base/logging.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "ui/views/controls/focusable_border.h" #include "ui/views/controls/focusable_border.h"
#include "ui/views/controls/scrollbar/base_scroll_bar_button.h" #include "ui/views/controls/scrollbar/base_scroll_bar_button.h"
#include "ui/views/controls/scrollbar/base_scroll_bar_thumb.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/scroll_bar.h" #include "ui/views/controls/scrollbar/scroll_bar.h"
namespace views { namespace views {
...@@ -70,18 +69,15 @@ class ScrollBarThumb : public BaseScrollBarThumb { ...@@ -70,18 +69,15 @@ class ScrollBarThumb : public BaseScrollBarThumb {
// ScrollBarButton // ScrollBarButton
ScrollBarButton::ScrollBarButton(ButtonListener* listener, Type type) ScrollBarButton::ScrollBarButton(ButtonListener* listener, Type type)
: BaseScrollBarButton(listener), : BaseScrollBarButton(listener), type_(type) {
type_(type) {
SetFocusBehavior(FocusBehavior::NEVER); SetFocusBehavior(FocusBehavior::NEVER);
} }
ScrollBarButton::~ScrollBarButton() { ScrollBarButton::~ScrollBarButton() {}
}
gfx::Size ScrollBarButton::GetPreferredSize() const { gfx::Size ScrollBarButton::GetPreferredSize() const {
return GetNativeTheme()->GetPartSize(GetNativeThemePart(), return GetNativeTheme()->GetPartSize(
GetNativeThemeState(), GetNativeThemePart(), GetNativeThemeState(), GetNativeThemeParams());
GetNativeThemeParams());
} }
void ScrollBarButton::OnPaint(gfx::Canvas* canvas) { void ScrollBarButton::OnPaint(gfx::Canvas* canvas) {
...@@ -91,8 +87,7 @@ void ScrollBarButton::OnPaint(gfx::Canvas* canvas) { ...@@ -91,8 +87,7 @@ void ScrollBarButton::OnPaint(gfx::Canvas* canvas) {
GetNativeThemeParams()); GetNativeThemeParams());
} }
ui::NativeTheme::ExtraParams ui::NativeTheme::ExtraParams ScrollBarButton::GetNativeThemeParams() const {
ScrollBarButton::GetNativeThemeParams() const {
ui::NativeTheme::ExtraParams params; ui::NativeTheme::ExtraParams params;
switch (state()) { switch (state()) {
...@@ -107,8 +102,7 @@ ui::NativeTheme::ExtraParams ...@@ -107,8 +102,7 @@ ui::NativeTheme::ExtraParams
return params; return params;
} }
ui::NativeTheme::Part ui::NativeTheme::Part ScrollBarButton::GetNativeThemePart() const {
ScrollBarButton::GetNativeThemePart() const {
switch (type_) { switch (type_) {
case UP: case UP:
return ui::NativeTheme::kScrollbarUpArrow; return ui::NativeTheme::kScrollbarUpArrow;
...@@ -124,8 +118,7 @@ ui::NativeTheme::Part ...@@ -124,8 +118,7 @@ ui::NativeTheme::Part
return ui::NativeTheme::kScrollbarUpArrow; return ui::NativeTheme::kScrollbarUpArrow;
} }
ui::NativeTheme::State ui::NativeTheme::State ScrollBarButton::GetNativeThemeState() const {
ScrollBarButton::GetNativeThemeState() const {
switch (state()) { switch (state()) {
case CustomButton::STATE_HOVERED: case CustomButton::STATE_HOVERED:
return ui::NativeTheme::kHovered; return ui::NativeTheme::kHovered;
...@@ -147,31 +140,24 @@ ui::NativeTheme::State ...@@ -147,31 +140,24 @@ ui::NativeTheme::State
// ScrollBarThumb // ScrollBarThumb
ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar) ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar)
: BaseScrollBarThumb(scroll_bar), : BaseScrollBarThumb(scroll_bar), scroll_bar_(scroll_bar) {}
scroll_bar_(scroll_bar) {
}
ScrollBarThumb::~ScrollBarThumb() { ScrollBarThumb::~ScrollBarThumb() {}
}
gfx::Size ScrollBarThumb::GetPreferredSize() const { gfx::Size ScrollBarThumb::GetPreferredSize() const {
return GetNativeTheme()->GetPartSize(GetNativeThemePart(), return GetNativeTheme()->GetPartSize(
GetNativeThemeState(), GetNativeThemePart(), GetNativeThemeState(), GetNativeThemeParams());
GetNativeThemeParams());
} }
void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) { void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) {
const gfx::Rect local_bounds(GetLocalBounds()); const gfx::Rect local_bounds(GetLocalBounds());
const ui::NativeTheme::State theme_state = GetNativeThemeState(); const ui::NativeTheme::State theme_state = GetNativeThemeState();
const ui::NativeTheme::ExtraParams extra_params(GetNativeThemeParams()); const ui::NativeTheme::ExtraParams extra_params(GetNativeThemeParams());
GetNativeTheme()->Paint(canvas->sk_canvas(), GetNativeTheme()->Paint(canvas->sk_canvas(), GetNativeThemePart(),
GetNativeThemePart(), theme_state, local_bounds, extra_params);
theme_state, const ui::NativeTheme::Part gripper_part =
local_bounds, scroll_bar_->IsHorizontal() ? ui::NativeTheme::kScrollbarHorizontalGripper
extra_params); : ui::NativeTheme::kScrollbarVerticalGripper;
const ui::NativeTheme::Part gripper_part = scroll_bar_->IsHorizontal() ?
ui::NativeTheme::kScrollbarHorizontalGripper :
ui::NativeTheme::kScrollbarVerticalGripper;
GetNativeTheme()->Paint(canvas->sk_canvas(), gripper_part, theme_state, GetNativeTheme()->Paint(canvas->sk_canvas(), gripper_part, theme_state,
local_bounds, extra_params); local_bounds, extra_params);
} }
...@@ -211,17 +197,13 @@ ui::NativeTheme::State ScrollBarThumb::GetNativeThemeState() const { ...@@ -211,17 +197,13 @@ ui::NativeTheme::State ScrollBarThumb::GetNativeThemeState() const {
} // namespace } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NativeScrollBarViews, public: // ScrollBarViews, public:
const char NativeScrollBarViews::kViewClassName[] = "NativeScrollBarViews";
NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar) const char ScrollBarViews::kViewClassName[] = "ScrollBarViews";
: BaseScrollBar(scroll_bar->IsHorizontal(),
new ScrollBarThumb(this)),
native_scroll_bar_(scroll_bar) {
set_controller(native_scroll_bar_->controller());
if (native_scroll_bar_->IsHorizontal()) { ScrollBarViews::ScrollBarViews(bool horizontal)
: BaseScrollBar(horizontal, new ScrollBarThumb(this)) {
if (horizontal) {
prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT); prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT);
next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT); next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT);
...@@ -242,28 +224,44 @@ NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar) ...@@ -242,28 +224,44 @@ NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar)
next_button_->set_context_menu_controller(this); next_button_->set_context_menu_controller(this);
} }
NativeScrollBarViews::~NativeScrollBarViews() { ScrollBarViews::~ScrollBarViews() {}
// static
int ScrollBarViews::GetVerticalScrollBarWidth(const ui::NativeTheme* theme) {
ui::NativeTheme::ExtraParams button_params;
button_params.scrollbar_arrow.is_hovering = false;
gfx::Size button_size =
theme->GetPartSize(ui::NativeTheme::kScrollbarUpArrow,
ui::NativeTheme::kNormal, button_params);
ui::NativeTheme::ExtraParams thumb_params;
thumb_params.scrollbar_thumb.is_hovering = false;
gfx::Size track_size =
theme->GetPartSize(ui::NativeTheme::kScrollbarVerticalThumb,
ui::NativeTheme::kNormal, thumb_params);
return std::max(track_size.width(), button_size.width());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NativeScrollBarViews, View overrides: // ScrollBarViews, View overrides:
void NativeScrollBarViews::Layout() { void ScrollBarViews::Layout() {
gfx::Size size = prev_button_->GetPreferredSize(); gfx::Size size = prev_button_->GetPreferredSize();
prev_button_->SetBounds(0, 0, size.width(), size.height()); prev_button_->SetBounds(0, 0, size.width(), size.height());
if (native_scroll_bar_->IsHorizontal()) { if (IsHorizontal()) {
next_button_->SetBounds(width() - size.width(), 0, next_button_->SetBounds(width() - size.width(), 0, size.width(),
size.width(), size.height()); size.height());
} else { } else {
next_button_->SetBounds(0, height() - size.height(), next_button_->SetBounds(0, height() - size.height(), size.width(),
size.width(), size.height()); size.height());
} }
GetThumb()->SetBoundsRect(GetTrackBounds()); GetThumb()->SetBoundsRect(GetTrackBounds());
} }
void NativeScrollBarViews::OnPaint(gfx::Canvas* canvas) { void ScrollBarViews::OnPaint(gfx::Canvas* canvas) {
gfx::Rect bounds = GetTrackBounds(); gfx::Rect bounds = GetTrackBounds();
if (bounds.IsEmpty()) if (bounds.IsEmpty())
...@@ -278,37 +276,25 @@ void NativeScrollBarViews::OnPaint(gfx::Canvas* canvas) { ...@@ -278,37 +276,25 @@ void NativeScrollBarViews::OnPaint(gfx::Canvas* canvas) {
GetNativeTheme()->Paint(canvas->sk_canvas(), part_, state_, bounds, params_); GetNativeTheme()->Paint(canvas->sk_canvas(), part_, state_, bounds, params_);
} }
gfx::Size NativeScrollBarViews::GetPreferredSize() const { gfx::Size ScrollBarViews::GetPreferredSize() const {
const ui::NativeTheme* theme = native_scroll_bar_->GetNativeTheme(); return gfx::Size(IsHorizontal() ? 0 : GetLayoutSize(),
if (native_scroll_bar_->IsHorizontal()) IsHorizontal() ? GetLayoutSize() : 0);
return gfx::Size(0, GetHorizontalScrollBarHeight(theme));
return gfx::Size(GetVerticalScrollBarWidth(theme), 0);
} }
const char* NativeScrollBarViews::GetClassName() const { const char* ScrollBarViews::GetClassName() const {
return kViewClassName; return kViewClassName;
} }
int NativeScrollBarViews::GetLayoutSize() const { int ScrollBarViews::GetLayoutSize() const {
gfx::Size size = prev_button_->GetPreferredSize(); const ui::NativeTheme* theme = GetNativeTheme();
return IsHorizontal() ? size.height() : size.width(); return IsHorizontal() ? GetHorizontalScrollBarHeight(theme)
} : GetVerticalScrollBarWidth(theme);
void NativeScrollBarViews::ScrollToPosition(int position) {
controller()->ScrollToPosition(native_scroll_bar_, position);
}
int NativeScrollBarViews::GetScrollIncrement(bool is_page, bool is_positive) {
return controller()->GetScrollIncrement(native_scroll_bar_,
is_page,
is_positive);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// BaseButton::ButtonListener overrides: // BaseButton::ButtonListener overrides:
void NativeScrollBarViews::ButtonPressed(Button* sender, void ScrollBarViews::ButtonPressed(Button* sender, const ui::Event& event) {
const ui::Event& event) {
if (sender == prev_button_) { if (sender == prev_button_) {
ScrollByAmount(SCROLL_PREV_LINE); ScrollByAmount(SCROLL_PREV_LINE);
} else if (sender == next_button_) { } else if (sender == next_button_) {
...@@ -317,31 +303,14 @@ void NativeScrollBarViews::ButtonPressed(Button* sender, ...@@ -317,31 +303,14 @@ void NativeScrollBarViews::ButtonPressed(Button* sender,
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NativeScrollBarViews, NativeScrollBarWrapper overrides: // ScrollBarViews, private:
int NativeScrollBarViews::GetPosition() const {
return BaseScrollBar::GetPosition();
}
View* NativeScrollBarViews::GetView() {
return this;
}
void NativeScrollBarViews::Update(int viewport_size,
int content_size,
int current_pos) {
BaseScrollBar::Update(viewport_size, content_size, current_pos);
}
////////////////////////////////////////////////////////////////////////////////
// NativeScrollBarViews, private:
gfx::Rect NativeScrollBarViews::GetTrackBounds() const { gfx::Rect ScrollBarViews::GetTrackBounds() const {
gfx::Rect bounds = GetLocalBounds(); gfx::Rect bounds = GetLocalBounds();
gfx::Size size = prev_button_->GetPreferredSize(); gfx::Size size = prev_button_->GetPreferredSize();
BaseScrollBarThumb* thumb = GetThumb(); BaseScrollBarThumb* thumb = GetThumb();
if (native_scroll_bar_->IsHorizontal()) { if (IsHorizontal()) {
bounds.set_x(bounds.x() + size.width()); bounds.set_x(bounds.x() + size.width());
bounds.set_width(std::max(0, bounds.width() - 2 * size.width())); bounds.set_width(std::max(0, bounds.width() - 2 * size.width()));
bounds.set_height(thumb->GetPreferredSize().height()); bounds.set_height(thumb->GetPreferredSize().height());
...@@ -354,53 +323,21 @@ gfx::Rect NativeScrollBarViews::GetTrackBounds() const { ...@@ -354,53 +323,21 @@ gfx::Rect NativeScrollBarViews::GetTrackBounds() const {
return bounds; return bounds;
} }
////////////////////////////////////////////////////////////////////////////////
// NativewScrollBarWrapper, public:
// static
NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper(
NativeScrollBar* scroll_bar) {
return new NativeScrollBarViews(scroll_bar);
}
// static // static
int NativeScrollBarWrapper::GetHorizontalScrollBarHeight( int ScrollBarViews::GetHorizontalScrollBarHeight(const ui::NativeTheme* theme) {
const ui::NativeTheme* theme) {
ui::NativeTheme::ExtraParams button_params; ui::NativeTheme::ExtraParams button_params;
button_params.scrollbar_arrow.is_hovering = false; button_params.scrollbar_arrow.is_hovering = false;
gfx::Size button_size = theme->GetPartSize( gfx::Size button_size =
ui::NativeTheme::kScrollbarLeftArrow, theme->GetPartSize(ui::NativeTheme::kScrollbarLeftArrow,
ui::NativeTheme::kNormal, ui::NativeTheme::kNormal, button_params);
button_params);
ui::NativeTheme::ExtraParams thumb_params; ui::NativeTheme::ExtraParams thumb_params;
thumb_params.scrollbar_thumb.is_hovering = false; thumb_params.scrollbar_thumb.is_hovering = false;
gfx::Size track_size = theme->GetPartSize( gfx::Size track_size =
ui::NativeTheme::kScrollbarHorizontalThumb, theme->GetPartSize(ui::NativeTheme::kScrollbarHorizontalThumb,
ui::NativeTheme::kNormal, ui::NativeTheme::kNormal, thumb_params);
thumb_params);
return std::max(track_size.height(), button_size.height()); return std::max(track_size.height(), button_size.height());
} }
// static
int NativeScrollBarWrapper::GetVerticalScrollBarWidth(
const ui::NativeTheme* theme) {
ui::NativeTheme::ExtraParams button_params;
button_params.scrollbar_arrow.is_hovering = false;
gfx::Size button_size = theme->GetPartSize(
ui::NativeTheme::kScrollbarUpArrow,
ui::NativeTheme::kNormal,
button_params);
ui::NativeTheme::ExtraParams thumb_params;
thumb_params.scrollbar_thumb.is_hovering = false;
gfx::Size track_size = theme->GetPartSize(
ui::NativeTheme::kScrollbarVerticalThumb,
ui::NativeTheme::kNormal,
thumb_params);
return std::max(track_size.width(), button_size.width());
}
} // namespace views } // namespace views
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_VIEWS_H_ #ifndef UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_VIEWS_H_
#define UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_VIEWS_H_ #define UI_VIEWS_CONTROLS_SCROLLBAR_SCROLL_BAR_VIEWS_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/scrollbar/base_scroll_bar.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" #include "ui/views/view.h"
namespace gfx { namespace gfx {
...@@ -20,20 +19,19 @@ class Canvas; ...@@ -20,20 +19,19 @@ class Canvas;
namespace views { namespace views {
class NativeScrollBar;
// Views implementation for the scrollbar. // Views implementation for the scrollbar.
class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar, class VIEWS_EXPORT ScrollBarViews : public BaseScrollBar,
public ButtonListener, public ButtonListener {
public NativeScrollBarWrapper {
public: public:
static const char kViewClassName[]; static const char kViewClassName[];
// Creates new scrollbar, either horizontal or vertical. // Creates new scrollbar, either horizontal or vertical.
explicit NativeScrollBarViews(NativeScrollBar* native_scroll_bar); explicit ScrollBarViews(bool horizontal);
~NativeScrollBarViews() override; ~ScrollBarViews() override;
private: static int GetVerticalScrollBarWidth(const ui::NativeTheme* theme);
protected:
// View overrides: // View overrides:
void Layout() override; void Layout() override;
void OnPaint(gfx::Canvas* canvas) override; void OnPaint(gfx::Canvas* canvas) override;
...@@ -43,24 +41,15 @@ class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar, ...@@ -43,24 +41,15 @@ class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar,
// ScrollBar overrides: // ScrollBar overrides:
int GetLayoutSize() const override; int GetLayoutSize() const override;
// BaseScrollBar overrides:
void ScrollToPosition(int position) override;
int GetScrollIncrement(bool is_page, bool is_positive) override;
// BaseButton::ButtonListener overrides: // BaseButton::ButtonListener overrides:
void ButtonPressed(Button* sender, const ui::Event& event) override; 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 // Returns the area for the track. This is the area of the scrollbar minus
// the size of the arrow buttons. // the size of the arrow buttons.
gfx::Rect GetTrackBounds() const override; gfx::Rect GetTrackBounds() const override;
// The NativeScrollBar we are bound to. private:
NativeScrollBar* native_scroll_bar_; static int GetHorizontalScrollBarHeight(const ui::NativeTheme* theme);
// The scroll bar buttons (Up/Down, Left/Right). // The scroll bar buttons (Up/Down, Left/Right).
Button* prev_button_; Button* prev_button_;
...@@ -70,9 +59,9 @@ class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar, ...@@ -70,9 +59,9 @@ class VIEWS_EXPORT NativeScrollBarViews : public BaseScrollBar,
ui::NativeTheme::Part part_; ui::NativeTheme::Part part_;
ui::NativeTheme::State state_; ui::NativeTheme::State state_;
DISALLOW_COPY_AND_ASSIGN(NativeScrollBarViews); DISALLOW_COPY_AND_ASSIGN(ScrollBarViews);
}; };
} // namespace views } // 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 @@ ...@@ -3,9 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "build/build_config.h" #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.h"
#include "ui/views/controls/scrollbar/scroll_bar_views.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -46,31 +45,26 @@ class TestScrollBarController : public views::ScrollBarController { ...@@ -46,31 +45,26 @@ class TestScrollBarController : public views::ScrollBarController {
namespace views { namespace views {
class NativeScrollBarTest : public ViewsTestBase { class ScrollBarViewsTest : public ViewsTestBase {
public: public:
NativeScrollBarTest() : widget_(NULL), scrollbar_(NULL) {} ScrollBarViewsTest() : widget_(nullptr), scrollbar_(nullptr) {}
void SetUp() override { void SetUp() override {
ViewsTestBase::SetUp(); ViewsTestBase::SetUp();
controller_.reset(new TestScrollBarController()); 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_ = new Widget;
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.bounds = gfx::Rect(0, 0, 100, 100); params.bounds = gfx::Rect(0, 0, 100, 100);
widget_->Init(params); widget_->Init(params);
View* container = new View(); View* container = new View();
widget_->SetContentsView(container); widget_->SetContentsView(container);
container->AddChildView(native_scrollbar_);
scrollbar_ = scrollbar_ = new ScrollBarViews(true);
static_cast<NativeScrollBarViews*>(native_scrollbar_->native_wrapper_);
scrollbar_->SetBounds(0, 0, 100, 100); scrollbar_->SetBounds(0, 0, 100, 100);
scrollbar_->Update(100, 1000, 0); scrollbar_->Update(100, 1000, 0);
scrollbar_->set_controller(controller_.get());
container->AddChildView(scrollbar_);
track_size_ = scrollbar_->GetTrackBounds().width(); track_size_ = scrollbar_->GetTrackBounds().width();
} }
...@@ -83,9 +77,6 @@ class NativeScrollBarTest : public ViewsTestBase { ...@@ -83,9 +77,6 @@ class NativeScrollBarTest : public ViewsTestBase {
protected: protected:
Widget* widget_; Widget* widget_;
// This is the native scrollbar the Views one wraps around.
NativeScrollBar* native_scrollbar_;
// This is the Views scrollbar. // This is the Views scrollbar.
BaseScrollBar* scrollbar_; BaseScrollBar* scrollbar_;
...@@ -106,7 +97,7 @@ class NativeScrollBarTest : public ViewsTestBase { ...@@ -106,7 +97,7 @@ class NativeScrollBarTest : public ViewsTestBase {
#define MAYBE_ScrollBarFitsToBottom ScrollBarFitsToBottom #define MAYBE_ScrollBarFitsToBottom ScrollBarFitsToBottom
#endif #endif
TEST_F(NativeScrollBarTest, MAYBE_Scrolling) { TEST_F(ScrollBarViewsTest, MAYBE_Scrolling) {
EXPECT_EQ(0, scrollbar_->GetPosition()); EXPECT_EQ(0, scrollbar_->GetPosition());
EXPECT_EQ(900, scrollbar_->GetMaxPosition()); EXPECT_EQ(900, scrollbar_->GetMaxPosition());
EXPECT_EQ(0, scrollbar_->GetMinPosition()); EXPECT_EQ(0, scrollbar_->GetMinPosition());
...@@ -114,7 +105,7 @@ TEST_F(NativeScrollBarTest, MAYBE_Scrolling) { ...@@ -114,7 +105,7 @@ TEST_F(NativeScrollBarTest, MAYBE_Scrolling) {
// Scroll to middle. // Scroll to middle.
scrollbar_->ScrollToThumbPosition(track_size_ / 2, true); scrollbar_->ScrollToThumbPosition(track_size_ / 2, true);
EXPECT_EQ(450, controller_->last_position); EXPECT_EQ(450, controller_->last_position);
EXPECT_EQ(native_scrollbar_, controller_->last_source); EXPECT_EQ(scrollbar_, controller_->last_source);
// Scroll to the end. // Scroll to the end.
scrollbar_->ScrollToThumbPosition(track_size_, true); scrollbar_->ScrollToThumbPosition(track_size_, true);
...@@ -144,7 +135,7 @@ TEST_F(NativeScrollBarTest, MAYBE_Scrolling) { ...@@ -144,7 +135,7 @@ TEST_F(NativeScrollBarTest, MAYBE_Scrolling) {
EXPECT_EQ(0, controller_->last_position); EXPECT_EQ(0, controller_->last_position);
} }
TEST_F(NativeScrollBarTest, MAYBE_ScrollBarFitsToBottom) { TEST_F(ScrollBarViewsTest, MAYBE_ScrollBarFitsToBottom) {
scrollbar_->Update(100, 1999, 0); scrollbar_->Update(100, 1999, 0);
EXPECT_EQ(0, scrollbar_->GetPosition()); EXPECT_EQ(0, scrollbar_->GetPosition());
EXPECT_EQ(1899, scrollbar_->GetMaxPosition()); EXPECT_EQ(1899, scrollbar_->GetMaxPosition());
...@@ -164,7 +155,7 @@ TEST_F(NativeScrollBarTest, MAYBE_ScrollBarFitsToBottom) { ...@@ -164,7 +155,7 @@ TEST_F(NativeScrollBarTest, MAYBE_ScrollBarFitsToBottom) {
scrollbar_->GetPosition()); scrollbar_->GetPosition());
} }
TEST_F(NativeScrollBarTest, ScrollToEndAfterShrinkAndExpand) { TEST_F(ScrollBarViewsTest, ScrollToEndAfterShrinkAndExpand) {
// Scroll to the end of the content. // Scroll to the end of the content.
scrollbar_->Update(100, 1001, 0); scrollbar_->Update(100, 1001, 0);
EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1)); EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1));
...@@ -175,7 +166,7 @@ TEST_F(NativeScrollBarTest, ScrollToEndAfterShrinkAndExpand) { ...@@ -175,7 +166,7 @@ TEST_F(NativeScrollBarTest, ScrollToEndAfterShrinkAndExpand) {
EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1)); EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1));
} }
TEST_F(NativeScrollBarTest, ThumbFullLengthOfTrack) { TEST_F(ScrollBarViewsTest, ThumbFullLengthOfTrack) {
// Shrink content so that it fits within the viewport. // Shrink content so that it fits within the viewport.
scrollbar_->Update(100, 10, 0); scrollbar_->Update(100, 10, 0);
EXPECT_EQ(scrollbar_->GetTrackBounds().width(), EXPECT_EQ(scrollbar_->GetTrackBounds().width(),
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h" #include "ui/views/controls/button/label_button_border.h"
#include "ui/views/controls/focusable_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) #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#define DESKTOP_LINUX #define DESKTOP_LINUX
...@@ -55,7 +55,7 @@ gfx::ImageSkia PlatformStyle::CreateComboboxArrow(bool is_enabled, ...@@ -55,7 +55,7 @@ gfx::ImageSkia PlatformStyle::CreateComboboxArrow(bool is_enabled,
// static // static
std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) { std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) {
return base::MakeUnique<NativeScrollBar>(is_horizontal); return base::MakeUnique<ScrollBarViews>(is_horizontal);
} }
// static // 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