summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-16 01:29:32 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-16 01:29:32 +0000
commit64caaf0a74177909785a195df4d3d47d0a4643a8 (patch)
treed526b5f2feaeefd53cbe54dbefd5feb88d17ce44 /ui
parent115a0e10a40f36265498446c0c8f7838a01bbbe6 (diff)
downloadchromium_src-64caaf0a74177909785a195df4d3d47d0a4643a8.zip
chromium_src-64caaf0a74177909785a195df4d3d47d0a4643a8.tar.gz
chromium_src-64caaf0a74177909785a195df4d3d47d0a4643a8.tar.bz2
Nukes NativeScrollBarWin and fixes bugs with getting
NativeScrollBarViews to work for windows. Here's the set of things fixed: . Couple of rendering issues. Size of thumb was wrong because of using wrong part. Wasn't painting gripper and state type was wrong. . RTL issues: needed to invert coordinate when dragging and checking for clicks in track was using wrong coordinates. BUG=170195 TEST=none Review URL: https://chromiumcodereview.appspot.com/11953002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177044 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/native_theme/native_theme_base.cc3
-rw-r--r--ui/native_theme/native_theme_win.cc6
-rw-r--r--ui/views/controls/scrollbar/base_scroll_bar.cc4
-rw-r--r--ui/views/controls/scrollbar/base_scroll_bar_thumb.cc2
-rw-r--r--ui/views/controls/scrollbar/native_scroll_bar_views.cc32
-rw-r--r--ui/views/controls/scrollbar/native_scroll_bar_win.cc353
-rw-r--r--ui/views/controls/scrollbar/native_scroll_bar_win.h66
-rw-r--r--ui/views/views.gyp2
8 files changed, 23 insertions, 445 deletions
diff --git a/ui/native_theme/native_theme_base.cc b/ui/native_theme/native_theme_base.cc
index 91a5172..7a833f6 100644
--- a/ui/native_theme/native_theme_base.cc
+++ b/ui/native_theme/native_theme_base.cc
@@ -210,7 +210,8 @@ void NativeThemeBase::Paint(SkCanvas* canvas,
break;
case kScrollbarHorizontalGripper:
case kScrollbarVerticalGripper:
- NOTIMPLEMENTED();
+ // Invoked by views scrollbar code, don't care about for non-win
+ // implementations, so no NOTIMPLEMENTED.
break;
case kSliderTrack:
PaintSliderTrack(canvas, state, rect, extra.slider);
diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc
index 0293405..3869334 100644
--- a/ui/native_theme/native_theme_win.cc
+++ b/ui/native_theme/native_theme_win.cc
@@ -1627,12 +1627,10 @@ int NativeThemeWin::GetWindowsPart(Part part,
part_id = SBP_ARROWBTN;
break;
case kScrollbarHorizontalThumb:
- part_id = extra.scrollbar_track.is_upper ? SBP_UPPERTRACKHORZ :
- SBP_LOWERTRACKHORZ;
+ part_id = SBP_THUMBBTNHORZ;
break;
case kScrollbarVerticalThumb:
- part_id = extra.scrollbar_track.is_upper ? SBP_UPPERTRACKVERT :
- SBP_LOWERTRACKVERT;
+ part_id = SBP_THUMBBTNVERT;
break;
default:
NOTREACHED() << "Invalid part: " << part;
diff --git a/ui/views/controls/scrollbar/base_scroll_bar.cc b/ui/views/controls/scrollbar/base_scroll_bar.cc
index 70287d4..9511117 100644
--- a/ui/views/controls/scrollbar/base_scroll_bar.cc
+++ b/ui/views/controls/scrollbar/base_scroll_bar.cc
@@ -413,9 +413,9 @@ void BaseScrollBar::ProcessPressEvent(const ui::LocatedEvent& event) {
SetThumbTrackState(CustomButton::STATE_PRESSED);
gfx::Rect thumb_bounds = thumb_->bounds();
if (IsHorizontal()) {
- if (event.x() < thumb_bounds.x()) {
+ if (GetMirroredXInView(event.x()) < thumb_bounds.x()) {
last_scroll_amount_ = SCROLL_PREV_PAGE;
- } else if (event.x() > thumb_bounds.right()) {
+ } else if (GetMirroredXInView(event.x()) > thumb_bounds.right()) {
last_scroll_amount_ = SCROLL_NEXT_PAGE;
}
} else {
diff --git a/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc b/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc
index b3f2491..8c58590 100644
--- a/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc
+++ b/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc
@@ -99,6 +99,8 @@ bool BaseScrollBarThumb::OnMouseDragged(const ui::MouseEvent& event) {
}
if (scroll_bar_->IsHorizontal()) {
int thumb_x = event.x() - mouse_offset_;
+ if (base::i18n::IsRTL())
+ thumb_x *= -1;
scroll_bar_->ScrollToThumbPosition(GetPosition() + thumb_x, false);
} else {
int thumb_y = event.y() - mouse_offset_;
diff --git a/ui/views/controls/scrollbar/native_scroll_bar_views.cc b/ui/views/controls/scrollbar/native_scroll_bar_views.cc
index ef69d64..06e96a2 100644
--- a/ui/views/controls/scrollbar/native_scroll_bar_views.cc
+++ b/ui/views/controls/scrollbar/native_scroll_bar_views.cc
@@ -173,26 +173,26 @@ gfx::Size ScrollBarThumb::GetPreferredSize() {
}
void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) {
+ const gfx::Rect local_bounds(GetLocalBounds());
+ const ui::NativeTheme::State theme_state = GetNativeThemeState();
+ const ui::NativeTheme::ExtraParams extra_params(GetNativeThemeParams());
GetNativeTheme()->Paint(canvas->sk_canvas(),
GetNativeThemePart(),
- GetNativeThemeState(),
- GetLocalBounds(),
- GetNativeThemeParams());
+ theme_state,
+ local_bounds,
+ extra_params);
+ const ui::NativeTheme::Part gripper_part = scroll_bar_->IsHorizontal() ?
+ ui::NativeTheme::kScrollbarHorizontalGripper :
+ ui::NativeTheme::kScrollbarVerticalGripper;
+ GetNativeTheme()->Paint(canvas->sk_canvas(), gripper_part, theme_state,
+ local_bounds, extra_params);
}
-ui::NativeTheme::ExtraParams
- ScrollBarThumb::GetNativeThemeParams() const {
+ui::NativeTheme::ExtraParams ScrollBarThumb::GetNativeThemeParams() const {
+ // This gives the behavior we want.
ui::NativeTheme::ExtraParams params;
-
- switch (GetState()) {
- case CustomButton::STATE_HOVERED:
- params.scrollbar_thumb.is_hovering = true;
- break;
- default:
- params.scrollbar_thumb.is_hovering = false;
- break;
- }
-
+ params.scrollbar_thumb.is_hovering =
+ (GetState() != CustomButton::STATE_HOVERED);
return params;
}
@@ -370,7 +370,6 @@ gfx::Rect NativeScrollBarViews::GetTrackBounds() const {
return bounds;
}
-#if defined(USE_AURA)
////////////////////////////////////////////////////////////////////////////////
// NativewScrollBarWrapper, public:
@@ -419,6 +418,5 @@ int NativeScrollBarWrapper::GetVerticalScrollBarWidth(
return std::max(track_size.width(), button_size.width());
}
-#endif
} // namespace views
diff --git a/ui/views/controls/scrollbar/native_scroll_bar_win.cc b/ui/views/controls/scrollbar/native_scroll_bar_win.cc
deleted file mode 100644
index c5c2012..0000000
--- a/ui/views/controls/scrollbar/native_scroll_bar_win.cc
+++ /dev/null
@@ -1,353 +0,0 @@
-// 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_win.h"
-
-#include <algorithm>
-#include <string>
-
-#include "base/message_loop.h"
-#include "ui/base/events/event.h"
-#include "ui/base/keycodes/keyboard_codes.h"
-#include "ui/base/win/hwnd_util.h"
-#include "ui/base/win/window_impl.h"
-#include "ui/views/controls/scrollbar/native_scroll_bar.h"
-#include "ui/views/controls/scrollbar/scroll_bar.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// ScrollBarContainer
-//
-// Since windows scrollbars only send notifications to their parent hwnd, we
-// use instances of this class to wrap native scrollbars.
-//
-/////////////////////////////////////////////////////////////////////////////
-class ScrollBarContainer : public ui::WindowImpl {
- public:
- explicit ScrollBarContainer(ScrollBar* parent)
- : parent_(parent),
- scrollbar_(NULL) {
- set_window_style(WS_CHILD);
- Init(parent->GetWidget()->GetNativeView(), gfx::Rect());
- ShowWindow(hwnd(), SW_SHOW);
- }
-
- virtual ~ScrollBarContainer() {
- }
-
- BEGIN_MSG_MAP_EX(ScrollBarContainer);
- MSG_WM_CREATE(OnCreate);
- MSG_WM_ERASEBKGND(OnEraseBkgnd);
- MSG_WM_PAINT(OnPaint);
- MSG_WM_SIZE(OnSize);
- MSG_WM_HSCROLL(OnHorizScroll);
- MSG_WM_VSCROLL(OnVertScroll);
- END_MSG_MAP();
-
- HWND GetScrollBarHWND() {
- return scrollbar_;
- }
-
- // Invoked when the scrollwheel is used
- void ScrollWithOffset(int o) {
- SCROLLINFO si;
- si.cbSize = sizeof(si);
- si.fMask = SIF_POS;
- GetScrollInfo(scrollbar_, SB_CTL, &si);
- int pos = si.nPos - o;
-
- if (pos < parent_->GetMinPosition())
- pos = parent_->GetMinPosition();
- else if (pos > parent_->GetMaxPosition())
- pos = parent_->GetMaxPosition();
-
- parent_->controller()->ScrollToPosition(parent_, pos);
-
- si.nPos = pos;
- si.fMask = SIF_POS;
- SetScrollInfo(scrollbar_, SB_CTL, &si, TRUE);
- }
-
- private:
-
- LRESULT OnCreate(LPCREATESTRUCT create_struct) {
- scrollbar_ = CreateWindowW(L"SCROLLBAR", L"",
- WS_CHILD | (parent_->IsHorizontal() ?
- SBS_HORZ : SBS_VERT),
- 0, 0, parent_->width(), parent_->height(),
- hwnd(), NULL, NULL, NULL);
- ui::CheckWindowCreated(scrollbar_);
- ShowWindow(scrollbar_, SW_SHOW);
- return 1;
- }
-
- LRESULT OnEraseBkgnd(HDC dc) {
- return 1;
- }
-
- void OnPaint(HDC ignore) {
- PAINTSTRUCT ps;
- HDC dc = BeginPaint(hwnd(), &ps);
- EndPaint(hwnd(), &ps);
- }
-
- void OnSize(int type, const CSize& sz) {
- SetWindowPos(scrollbar_,
- 0, 0, 0, sz.cx, sz.cy,
- SWP_DEFERERASE | SWP_NOACTIVATE | SWP_NOCOPYBITS |
- SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER);
- }
-
- void OnScroll(int code, HWND source, bool is_horizontal) {
- int pos;
-
- if (code == SB_ENDSCROLL) {
- return;
- }
-
- // If we receive an event from the scrollbar, make the view
- // component focused so we actually get mousewheel events.
- if (source != NULL) {
- Widget* widget = parent_->GetWidget();
- if (widget && widget->GetNativeView() != GetFocus()) {
- parent_->RequestFocus();
- }
- }
-
- SCROLLINFO si;
- si.cbSize = sizeof(si);
- si.fMask = SIF_POS | SIF_TRACKPOS;
- GetScrollInfo(scrollbar_, SB_CTL, &si);
- pos = si.nPos;
-
- ScrollBarController* sbc = parent_->controller();
-
- switch (code) {
- case SB_BOTTOM: // case SB_RIGHT:
- pos = parent_->GetMaxPosition();
- break;
- case SB_TOP: // case SB_LEFT:
- pos = parent_->GetMinPosition();
- break;
- case SB_LINEDOWN: // case SB_LINERIGHT:
- pos += sbc->GetScrollIncrement(parent_, false, true);
- pos = std::min(parent_->GetMaxPosition(), pos);
- break;
- case SB_LINEUP: // case SB_LINELEFT:
- pos -= sbc->GetScrollIncrement(parent_, false, false);
- pos = std::max(parent_->GetMinPosition(), pos);
- break;
- case SB_PAGEDOWN: // case SB_PAGERIGHT:
- pos += sbc->GetScrollIncrement(parent_, true, true);
- pos = std::min(parent_->GetMaxPosition(), pos);
- break;
- case SB_PAGEUP: // case SB_PAGELEFT:
- pos -= sbc->GetScrollIncrement(parent_, true, false);
- pos = std::max(parent_->GetMinPosition(), pos);
- break;
- case SB_THUMBPOSITION:
- case SB_THUMBTRACK:
- pos = si.nTrackPos;
- if (pos < parent_->GetMinPosition())
- pos = parent_->GetMinPosition();
- else if (pos > parent_->GetMaxPosition())
- pos = parent_->GetMaxPosition();
- break;
- default:
- break;
- }
-
- sbc->ScrollToPosition(parent_, pos);
-
- si.nPos = pos;
- si.fMask = SIF_POS;
- SetScrollInfo(scrollbar_, SB_CTL, &si, TRUE);
-
- // Note: the system scrollbar modal loop doesn't give a chance
- // to our message_loop so we need to call DidProcessMessage()
- // manually.
- //
- // Sadly, we don't know what message has been processed. We may
- // want to remove the message from DidProcessMessage()
- MSG dummy;
- dummy.hwnd = NULL;
- dummy.message = 0;
- MessageLoopForUI::current()->DidProcessMessage(dummy);
- }
-
- // note: always ignore 2nd param as it is 16 bits
- void OnHorizScroll(int n_sb_code, int ignore, HWND source) {
- OnScroll(n_sb_code, source, true);
- }
-
- // note: always ignore 2nd param as it is 16 bits
- void OnVertScroll(int n_sb_code, int ignore, HWND source) {
- OnScroll(n_sb_code, source, false);
- }
-
- ScrollBar* parent_;
- HWND scrollbar_;
-
- DISALLOW_COPY_AND_ASSIGN(ScrollBarContainer);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// NativeScrollBarWin, public:
-
-NativeScrollBarWin::NativeScrollBarWin(NativeScrollBar* scroll_bar)
- : native_scroll_bar_(scroll_bar),
- sb_container_(NULL) {
- set_focus_view(scroll_bar);
- memset(&scroll_info_, 0, sizeof(scroll_info_));
-}
-
-NativeScrollBarWin::~NativeScrollBarWin() {
- if (sb_container_.get()) {
- // We always destroy the scrollbar container explicitly to cover all
- // cases including when the container is no longer connected to a
- // widget tree.
- DestroyWindow(sb_container_->hwnd());
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// NativeScrollBarWin, View overrides:
-
-void NativeScrollBarWin::Layout() {
- NativeControlWin::Layout();
-}
-
-gfx::Size NativeScrollBarWin::GetPreferredSize() {
- const ui::NativeTheme* theme = native_scroll_bar_->GetNativeTheme();
- if (native_scroll_bar_->IsHorizontal())
- return gfx::Size(0, GetHorizontalScrollBarHeight(theme));
- return gfx::Size(GetVerticalScrollBarWidth(theme), 0);
-}
-
-bool NativeScrollBarWin::OnKeyPressed(const ui::KeyEvent& event) {
- if (!sb_container_.get())
- return false;
- int code = -1;
- switch (event.key_code()) {
- case ui::VKEY_UP:
- if (!native_scroll_bar_->IsHorizontal())
- code = SB_LINEUP;
- break;
- case ui::VKEY_PRIOR:
- code = SB_PAGEUP;
- break;
- case ui::VKEY_NEXT:
- code = SB_PAGEDOWN;
- break;
- case ui::VKEY_DOWN:
- if (!native_scroll_bar_->IsHorizontal())
- code = SB_LINEDOWN;
- break;
- case ui::VKEY_HOME:
- code = SB_TOP;
- break;
- case ui::VKEY_END:
- code = SB_BOTTOM;
- break;
- case ui::VKEY_LEFT:
- if (native_scroll_bar_->IsHorizontal())
- code = SB_LINELEFT;
- break;
- case ui::VKEY_RIGHT:
- if (native_scroll_bar_->IsHorizontal())
- code = SB_LINERIGHT;
- break;
- }
- if (code != -1) {
- SendMessage(sb_container_->hwnd(),
- native_scroll_bar_->IsHorizontal() ? WM_HSCROLL : WM_VSCROLL,
- MAKELONG(static_cast<WORD>(code), 0), 0L);
- return true;
- }
- return false;
-}
-
-bool NativeScrollBarWin::OnMouseWheel(const ui::MouseWheelEvent& e) {
- if (!sb_container_.get())
- return false;
- sb_container_->ScrollWithOffset(e.offset());
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// NativeScrollBarWin, NativeControlWin overrides:
-
-void NativeScrollBarWin::CreateNativeControl() {
- sb_container_.reset(new ScrollBarContainer(native_scroll_bar_));
- NativeControlCreated(sb_container_->hwnd());
- // Reinstall scroll state if we have valid information.
- if (scroll_info_.cbSize)
- SetScrollInfo(sb_container_->GetScrollBarHWND(), SB_CTL, &scroll_info_,
- TRUE);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// NativeScrollBarWin, NativeScrollBarWrapper overrides:
-
-int NativeScrollBarWin::GetPosition() const {
- SCROLLINFO si;
- si.cbSize = sizeof(si);
- si.fMask = SIF_POS;
- GetScrollInfo(sb_container_->GetScrollBarHWND(), SB_CTL, &si);
- return si.nPos;
-}
-
-View* NativeScrollBarWin::GetView() {
- return this;
-}
-
-void NativeScrollBarWin::Update(int viewport_size,
- int content_size,
- int current_pos) {
- if (!sb_container_.get())
- return;
-
- if (content_size < 0)
- content_size = 0;
-
- if (current_pos < 0)
- current_pos = 0;
-
- if (current_pos > content_size)
- current_pos = content_size;
-
- scroll_info_.cbSize = sizeof(scroll_info_);
- scroll_info_.fMask = SIF_DISABLENOSCROLL | SIF_POS | SIF_RANGE | SIF_PAGE;
- scroll_info_.nMin = 0;
- scroll_info_.nMax = content_size;
- scroll_info_.nPos = current_pos;
- scroll_info_.nPage = viewport_size;
- SetScrollInfo(sb_container_->GetScrollBarHWND(), SB_CTL, &scroll_info_, TRUE);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// NativewScrollBarWrapper, public:
-
-// static
-NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper(
- NativeScrollBar* scroll_bar) {
- return new NativeScrollBarWin(scroll_bar);
-}
-
-// static
-int NativeScrollBarWrapper::GetHorizontalScrollBarHeight(
- const ui::NativeTheme* theme) {
- return GetSystemMetrics(SM_CYHSCROLL);
-}
-
-// static
-int NativeScrollBarWrapper::GetVerticalScrollBarWidth(
- const ui::NativeTheme* theme) {
- return GetSystemMetrics(SM_CXVSCROLL);
-}
-
-} // namespace views
diff --git a/ui/views/controls/scrollbar/native_scroll_bar_win.h b/ui/views/controls/scrollbar/native_scroll_bar_win.h
deleted file mode 100644
index ab70653..0000000
--- a/ui/views/controls/scrollbar/native_scroll_bar_win.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// 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_WIN_H_
-#define UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_WIN_H_
-
-#include "ui/views/controls/native_control_win.h"
-#include "ui/views/controls/scrollbar/native_scroll_bar_wrapper.h"
-
-namespace views {
-
-class ScrollBarContainer;
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// NativeScrollBarWin
-//
-// A View subclass that wraps a Native Windows scrollbar control.
-//
-// A scrollbar is either horizontal or vertical.
-//
-/////////////////////////////////////////////////////////////////////////////
-class NativeScrollBarWin : public NativeControlWin,
- public NativeScrollBarWrapper {
- public:
- // Create new scrollbar, either horizontal or vertical.
- explicit NativeScrollBarWin(NativeScrollBar* native_scroll_bar);
- virtual ~NativeScrollBarWin();
-
- private:
- // Overridden from View for layout purpose.
- virtual void Layout();
- virtual gfx::Size GetPreferredSize();
-
- // Overridden from View for keyboard UI purpose.
- virtual bool OnKeyPressed(const ui::KeyEvent& event);
- virtual bool OnMouseWheel(const ui::MouseWheelEvent& e);
-
- // Overridden from NativeControlWin.
- virtual void CreateNativeControl();
-
- // Overridden from ScrollBarWrapper.
- virtual int GetPosition() const;
- virtual View* GetView();
- virtual void Update(int viewport_size, int content_size, int current_pos);
-
- // The NativeScrollBar we are bound to.
- NativeScrollBar* native_scroll_bar_;
-
- // sb_container_ is a custom hwnd that we use to wrap the real
- // windows scrollbar. We need to do this to get the scroll events
- // without having to do anything special in the high level hwnd.
- scoped_ptr<ScrollBarContainer> sb_container_;
-
- // Last scrollbar state we wrote to the scrollbar. We keep it here, so we can
- // reinitialize the scrollbar to its previous state in case it gets hidden and
- // recreated.
- SCROLLINFO scroll_info_;
-
- DISALLOW_COPY_AND_ASSIGN(NativeScrollBarWin);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_CONTROLS_SCROLLBAR_NATIVE_SCROLL_BAR_WIN_H_
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index a7c38b4..8a100fd 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -181,8 +181,6 @@
'controls/scrollbar/bitmap_scroll_bar.h',
'controls/scrollbar/native_scroll_bar_views.cc',
'controls/scrollbar/native_scroll_bar_views.h',
- 'controls/scrollbar/native_scroll_bar_win.cc',
- 'controls/scrollbar/native_scroll_bar_win.h',
'controls/scrollbar/native_scroll_bar_wrapper.h',
'controls/scrollbar/native_scroll_bar.cc',
'controls/scrollbar/native_scroll_bar.h',