diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-12 02:08:11 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-12 02:08:11 +0000 |
commit | 039a1dad907b8c163532b0597d86bf31dedb9a9b (patch) | |
tree | abb1c24331258269fe61c816e37e3a094248ab42 /chrome | |
parent | e8d5545b55d44c8b9f05d550dab052fcfe392f2d (diff) | |
download | chromium_src-039a1dad907b8c163532b0597d86bf31dedb9a9b.zip chromium_src-039a1dad907b8c163532b0597d86bf31dedb9a9b.tar.gz chromium_src-039a1dad907b8c163532b0597d86bf31dedb9a9b.tar.bz2 |
Update the Pepper scrollbar widget to use the new WebKit Scrollbar interface.
Review URL: http://codereview.chromium.org/2008008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47000 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/chrome_renderer.gypi | 3 | ||||
-rw-r--r-- | chrome/renderer/pepper_scrollbar_widget.cc | 732 | ||||
-rw-r--r-- | chrome/renderer/pepper_scrollbar_widget.h | 208 | ||||
-rw-r--r-- | chrome/renderer/pepper_scrollbar_widget_linux.cc | 244 | ||||
-rw-r--r-- | chrome/renderer/pepper_scrollbar_widget_mac.mm | 34 | ||||
-rw-r--r-- | chrome/renderer/pepper_scrollbar_widget_win.cc | 199 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 10 |
7 files changed, 225 insertions, 1205 deletions
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 854d15e..1c2520c 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -109,9 +109,6 @@ 'renderer/pepper_devices.h', 'renderer/pepper_scrollbar_widget.cc', 'renderer/pepper_scrollbar_widget.h', - 'renderer/pepper_scrollbar_widget_linux.cc', - 'renderer/pepper_scrollbar_widget_mac.mm', - 'renderer/pepper_scrollbar_widget_win.cc', 'renderer/pepper_widget.cc', 'renderer/pepper_widget.h', 'renderer/plugin_channel_host.cc', diff --git a/chrome/renderer/pepper_scrollbar_widget.cc b/chrome/renderer/pepper_scrollbar_widget.cc index 4d45200..16d0eee 100644 --- a/chrome/renderer/pepper_scrollbar_widget.cc +++ b/chrome/renderer/pepper_scrollbar_widget.cc @@ -7,82 +7,159 @@ #include "base/basictypes.h" #include "base/keyboard_codes.h" #include "base/logging.h" +#include "base/message_loop.h" #include "chrome/renderer/pepper_devices.h" #include "skia/ext/platform_canvas.h" #include "skia/ext/platform_device.h" +#include "third_party/WebKit/WebKit/chromium/public/WebScrollBar.h" #include "webkit/glue/plugins/plugin_instance.h" -const int PepperScrollbarWidget::kPixelsPerLine = 40; -const float PepperScrollbarWidget::kMinFractionToStepWhenPaging = 0.875f; -#if !defined(OS_MACOSX) -const int PepperScrollbarWidget::kMaxOverlapBetweenPages = kint32max; -#endif -const float PepperScrollbarWidget::kInitialAutoscrollTimerDelay = 0.25f; -const float PepperScrollbarWidget::kAutoscrollTimerDelay = 0.05f; +using WebKit::WebInputEvent; +using WebKit::WebKeyboardEvent; +using WebKit::WebMouseEvent; +using WebKit::WebMouseWheelEvent; +using WebKit::WebRect; +using WebKit::WebScrollbar; +using WebKit::WebVector; + + +// Anonymous namespace for functions converting NPAPI to WebInputEvents types. +namespace { +WebKeyboardEvent BuildKeyEvent(const NPPepperEvent& event) { + WebKeyboardEvent key_event; + switch (event.type) { + case NPEventType_RawKeyDown: + key_event.type = WebInputEvent::RawKeyDown; + break; + case NPEventType_KeyDown: + key_event.type = WebInputEvent::KeyDown; + break; + case NPEventType_KeyUp: + key_event.type = WebInputEvent::KeyUp; + break; + } + key_event.timeStampSeconds = event.timeStampSeconds; + key_event.modifiers = event.u.key.modifier; + key_event.windowsKeyCode = event.u.key.normalizedKeyCode; + return key_event; +} + +WebKeyboardEvent BuildCharEvent(const NPPepperEvent& event) { + WebKeyboardEvent key_event; + key_event.type = WebInputEvent::Char; + key_event.timeStampSeconds = event.timeStampSeconds; + key_event.modifiers = event.u.character.modifier; + // For consistency, check that the sizes of the texts agree. + DCHECK(sizeof(event.u.character.text) == sizeof(key_event.text)); + DCHECK(sizeof(event.u.character.unmodifiedText) == + sizeof(key_event.unmodifiedText)); + for (size_t i = 0; i < WebKeyboardEvent::textLengthCap; ++i) { + key_event.text[i] = event.u.character.text[i]; + key_event.unmodifiedText[i] = event.u.character.unmodifiedText[i]; + } + return key_event; +} + +WebMouseEvent BuildMouseEvent(const NPPepperEvent& event) { + WebMouseEvent mouse_event; + switch (event.type) { + case NPEventType_MouseDown: + mouse_event.type = WebInputEvent::MouseDown; + break; + case NPEventType_MouseUp: + mouse_event.type = WebInputEvent::MouseUp; + break; + case NPEventType_MouseMove: + mouse_event.type = WebInputEvent::MouseMove; + break; + case NPEventType_MouseEnter: + mouse_event.type = WebInputEvent::MouseEnter; + break; + case NPEventType_MouseLeave: + mouse_event.type = WebInputEvent::MouseLeave; + break; + } + mouse_event.timeStampSeconds = event.timeStampSeconds; + mouse_event.modifiers = event.u.mouse.modifier; + mouse_event.button = static_cast<WebMouseEvent::Button>(event.u.mouse.button); + mouse_event.x = event.u.mouse.x; + mouse_event.y = event.u.mouse.y; + mouse_event.clickCount = event.u.mouse.clickCount; + return mouse_event; +} + +WebMouseWheelEvent BuildMouseWheelEvent(const NPPepperEvent& event) { + WebMouseWheelEvent mouse_wheel_event; + mouse_wheel_event.type = WebInputEvent::MouseWheel; + mouse_wheel_event.timeStampSeconds = event.timeStampSeconds; + mouse_wheel_event.modifiers = event.u.wheel.modifier; + mouse_wheel_event.deltaX = event.u.wheel.deltaX; + mouse_wheel_event.deltaY = event.u.wheel.deltaY; + mouse_wheel_event.wheelTicksX = event.u.wheel.wheelTicksX; + mouse_wheel_event.wheelTicksY = event.u.wheel.wheelTicksY; + mouse_wheel_event.scrollByPage = event.u.wheel.scrollByPage; + return mouse_wheel_event; +} + +} // namespace PepperScrollbarWidget::PepperScrollbarWidget( - const NPScrollbarCreateParams& params) - : vertical_(params.vertical), - enabled_(true), - length_(0), - total_length_(0), - pixels_per_page_(0), - thickness_(0), - arrow_length_(0), - hovered_part_(-1), - pressed_part_(-1), - thumb_position_(0), - have_mouse_capture_(false), - drag_origin_(-1.0), - pressed_position_(-1) { - GenerateMeasurements(); + const NPScrollbarCreateParams& params) { + scrollbar_.reset(WebScrollbar::create( + static_cast<WebKit::WebScrollbarClient*>(this), + params.vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal)); + AddRef(); } PepperScrollbarWidget::~PepperScrollbarWidget() { - StopTimerIfNeeded(); } void PepperScrollbarWidget::Destroy() { - delete this; + Release(); +} + +void PepperScrollbarWidget::Paint(Graphics2DDeviceContext* context, + const NPRect& dirty) { + gfx::Rect rect(dirty.left, dirty.top, dirty.right - dirty.left, + dirty.bottom - dirty.top); +#if defined(OS_WIN) || defined(OS_LINUX) + scrollbar_->paint(context->canvas(), rect); +#elif defined(OS_MACOSX) + // TODO(port) +#endif + dirty_rect_ = dirty_rect_.Subtract(rect); } bool PepperScrollbarWidget::HandleEvent(const NPPepperEvent& event) { bool rv = false; + switch (event.type) { + case NPEventType_Undefined: + return false; case NPEventType_MouseDown: - rv = OnMouseDown(event); - break; case NPEventType_MouseUp: - rv = OnMouseUp(event); - break; case NPEventType_MouseMove: - rv = OnMouseMove(event); - break; case NPEventType_MouseEnter: - break; case NPEventType_MouseLeave: - rv = OnMouseLeave(event); + rv = scrollbar_->handleInputEvent(BuildMouseEvent(event)); break; case NPEventType_MouseWheel: - rv = OnMouseWheel(event); + rv = scrollbar_->handleInputEvent(BuildMouseWheelEvent(event)); break; + case NPEventType_RawKeyDown: case NPEventType_KeyDown: - rv = OnKeyDown(event); - break; case NPEventType_KeyUp: - rv = OnKeyUp(event); + rv = scrollbar_->handleInputEvent(BuildKeyEvent(event)); break; - default: + case NPEventType_Char: + rv = scrollbar_->handleInputEvent(BuildCharEvent(event)); + break; + case NPEventType_Minimize: + case NPEventType_Focus: + case NPEventType_Device: + // NOTIMPLEMENTED(); break; - } - - if (rv) { - dirty_rect_ = dirty_rect_.Union(gfx::Rect( - location_, - gfx::Size(vertical_ ? thickness_: length_, - vertical_ ? length_ : thickness_))); - WidgetPropertyChanged(NPWidgetPropertyDirtyRect); } return rv; @@ -91,23 +168,30 @@ bool PepperScrollbarWidget::HandleEvent(const NPPepperEvent& event) { void PepperScrollbarWidget::GetProperty( NPWidgetProperty property, void* value) { switch (property) { + case NPWidgetPropertyLocation: { + NPRect* rv = static_cast<NPRect*>(value); + rv->left = location_.x(); + rv->top = location_.y(); + rv->right = location_.right(); + rv->bottom = location_.bottom(); + break; + } case NPWidgetPropertyDirtyRect: { NPRect* rv = reinterpret_cast<NPRect*>(value); rv->left = dirty_rect_.x(); rv->top = dirty_rect_.y(); rv->right = dirty_rect_.right(); rv->bottom = dirty_rect_.bottom(); - dirty_rect_ = gfx::Rect(); break; } case NPWidgetPropertyScrollbarThickness: { int32* rv = static_cast<int32*>(value); - *rv = thickness_; + *rv = WebScrollbar::defaultThickness(); break; } - case NPWidgetPropertyScrollbarPosition: { + case NPWidgetPropertyScrollbarValue: { int32* rv = static_cast<int32*>(value); - *rv = GetPosition(); + *rv = scrollbar_->value(); break; } default: @@ -121,513 +205,95 @@ void PepperScrollbarWidget::SetProperty( switch (property) { case NPWidgetPropertyLocation: { NPRect* r = static_cast<NPRect*>(value); - gfx::Point location(r->left, r->top); - gfx::Size size(r->right - r->left, r->bottom - r->top); - SetLocation(location, - vertical_ ? size.height() : size.width(), - total_length_); + location_ = gfx::Rect( + r->left, r->top, r->right - r->left, r->bottom - r->top); + scrollbar_->setLocation(location_); break; } - case NPWidgetPropertyScrollbarPosition: { + case NPWidgetPropertyScrollbarValue: { int32* position = static_cast<int*>(value); - ScrollTo(*position); + scrollbar_->setValue(*position); break; } case NPWidgetPropertyScrollbarDocumentSize: { int32* total_length = static_cast<int32*>(value); - SetLocation(location_, length_, *total_length); - break; - } - case NPWidgetPropertyScrollbarTickMarks: - break; - case NPWidgetPropertyScrollbarScrollByLine: { - bool* forward = static_cast<bool*>(value); - Scroll(!forward, SCROLL_BY_LINE, 0); - break; - } - case NPWidgetPropertyScrollbarScrollByPage: { - bool* forward = static_cast<bool*>(value); - Scroll(!forward, SCROLL_BY_PAGE, 0); + scrollbar_->setDocumentSize(*total_length); break; } - case NPWidgetPropertyScrollbarScrollByDocument: { - bool* forward = static_cast<bool*>(value); - Scroll(!forward, SCROLL_BY_DOCUMENT, 0); + case NPWidgetPropertyScrollbarTickMarks: { + NPScrollbarTickMarks* tickmarks = + static_cast<NPScrollbarTickMarks*>(value); + tickmarks_.resize(tickmarks->count); + for (uint32 i = 0; i < tickmarks->count; ++i) { + WebRect rect( + tickmarks->tickmarks[i].left, + tickmarks->tickmarks[i].top, + tickmarks->tickmarks[i].right - tickmarks->tickmarks[i].left, + tickmarks->tickmarks[i].bottom - tickmarks->tickmarks[i].top); + tickmarks_[i] = rect; + } + dirty_rect_ = location_; + NotifyInvalidate(); break; } + case NPWidgetPropertyScrollbarScrollByLine: + case NPWidgetPropertyScrollbarScrollByPage: + case NPWidgetPropertyScrollbarScrollByDocument: case NPWidgetPropertyScrollbarScrollByPixels: { - int32 pixels = *static_cast<int32*>(value); - bool forward = pixels >= 0; - if (pixels < 0) - pixels *= -1; - Scroll(!forward, SCROLL_BY_PIXELS, pixels); - break; - } - default: - NOTREACHED(); - break; - } -} - -void PepperScrollbarWidget::SetLocation( - const gfx::Point& location, int length, int total_length) { - location_ = location; - length_ = length; - total_length_ = total_length; - - // As a result of zooming out, the thumb's current position might need to be - // updated. - if (thumb_position_ > MaximumThumbPosition()) - SetPosition(static_cast<float>(MaximumThumbPosition()), true); - - pixels_per_page_ = std::max<int>(std::max<int>( - static_cast<int>(length_ * kMinFractionToStepWhenPaging), - length_ - kMaxOverlapBetweenPages), 1); - - - // did this above tho inside setpositoin... - dirty_rect_ = dirty_rect_.Union(gfx::Rect( - location_, - gfx::Size(vertical_ ? thickness_: length_, - vertical_ ? length_ : thickness_))); - WidgetPropertyChanged(NPWidgetPropertyDirtyRect); -} - -gfx::Rect PepperScrollbarWidget::GetLocation() const { - return gfx::Rect(location_.x(), - location_.y(), - vertical_ ? thickness_ : length_, - vertical_ ? length_ : thickness_); -} - -int PepperScrollbarWidget::GetPosition() const { - return static_cast<int>(thumb_position_ * (total_length_ - length_) / - MaximumThumbPosition()); -} - -bool PepperScrollbarWidget::OnMouseDown(const NPPepperEvent& event) { - if (event.u.mouse.button == NPMouseButton_Right) - return false; - - gfx::Point location(event.u.mouse.x, event.u.mouse.y); - int pressed_part = HitTest(location); - if (pressed_part == -1) - return false; - - have_mouse_capture_ = true; - - pressed_part_ = pressed_part; - int pressed_position = ThumbPosition(location); - if (IsThumb(pressed_part_)) { - pressed_position_ = pressed_position; - drag_origin_ = thumb_position_; - return true; - } else if (IsTrackbar(pressed_part_) && ShouldCenterOnThumb(event)) { - hovered_part_ = pressed_part_ = vertical_ ? - VERTICAL_THUMB : HORIZONTAL_THUMB; - drag_origin_ = thumb_position_; - // Need to mark the middle of the thumb as the pressed position so that when - // it's moved, the delta will be from the current pixel position of the - // thumb to its new position. - pressed_position_ = static_cast<int>(thumb_position_) + ThumbLength() / 2; - MoveThumb(pressed_position); - return true; - } - - pressed_position_ = pressed_position; - DCHECK(IsArrow(pressed_part_) || IsTrackbar(pressed_part_)); - - AutoScroll(kInitialAutoscrollTimerDelay); - - return true; -} - -bool PepperScrollbarWidget::OnMouseUp(const NPPepperEvent& event) { - if (event.u.mouse.button != NPMouseButton_Left) - return false; - - pressed_part_ = -1; - pressed_position_ = -1; - drag_origin_ = -1.0; - StopTimerIfNeeded(); - - gfx::Point location(event.u.mouse.x, event.u.mouse.y); - return HitTest(location) != -1; -} - -bool PepperScrollbarWidget::OnMouseMove(const NPPepperEvent& event) { - gfx::Point location(event.u.mouse.x, event.u.mouse.y); - if (IsThumb(pressed_part_)) { - if (ShouldSnapBack(location)) { - SetPosition(drag_origin_, true); - } else { - MoveThumb(ThumbPosition(location)); - } - return true; - } - - if (pressed_part_ != -1) - pressed_position_ = ThumbPosition(location); - - int part = HitTest(location); - if (part != hovered_part_) { - if (pressed_part_ != -1) { - if (part == pressed_part_) { - // The mouse just moved back over the pressed part. Need to start the - // timers again. - StartTimerIfNeeded(kAutoscrollTimerDelay); - } else if (hovered_part_ == pressed_part_) { - // The mouse is leaving the pressed part. Stop the timer. - StopTimerIfNeeded(); + bool forward; + float multiplier = 1.0; + + WebScrollbar::ScrollGranularity granularity; + if (property == NPWidgetPropertyScrollbarScrollByLine) { + forward = *static_cast<bool*>(value); + granularity = WebScrollbar::ScrollByLine; + } else if (property == NPWidgetPropertyScrollbarScrollByLine) { + forward = *static_cast<bool*>(value); + granularity = WebScrollbar::ScrollByPage; + } else if (property == NPWidgetPropertyScrollbarScrollByLine) { + forward = *static_cast<bool*>(value); + granularity = WebScrollbar::ScrollByDocument; + } else { + multiplier = static_cast<float>(*static_cast<int32*>(value)); + forward = multiplier >= 0; + if (multiplier < 0) + multiplier *= -1; + granularity = WebScrollbar::ScrollByPixel; } + scrollbar_->scroll( + forward ? WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward, + granularity, multiplier); + break; } - - hovered_part_ = part; - return true; } - - return false; } -bool PepperScrollbarWidget::OnMouseLeave(const NPPepperEvent& event) { - hovered_part_ = -1; - return have_mouse_capture_; +void PepperScrollbarWidget::valueChanged(WebScrollbar*) { + WidgetPropertyChanged(NPWidgetPropertyScrollbarValue); } -bool PepperScrollbarWidget::OnMouseWheel(const NPPepperEvent& event) { - // TODO(jabdelmalek): handle middle clicking and moving the mouse diagonaly, - // which would give both deltaX and deltaY. - int delta = static_cast<int>( - vertical_ ? event.u.wheel.deltaY : event.u.wheel.deltaX); - // Delta is negative for down/right. - bool backwards = delta > 0; - if (delta < 0) - delta = -delta; - if (delta != 0) { - if (event.u.wheel.scrollByPage) { - Scroll(backwards, SCROLL_BY_PAGE, 0); - } else { - Scroll(backwards, SCROLL_BY_PIXELS, delta); - } - } - - return delta != 0; +void PepperScrollbarWidget::invalidateScrollbarRect(WebScrollbar*, + const WebRect& rect) { + dirty_rect_ = dirty_rect_.Union(rect); + // Can't call into the client to tell them about the invalidate right away, + // since the Scrollbar code is still in the middle of updating its internal + // state. + MessageLoop::current()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &PepperScrollbarWidget::NotifyInvalidate)); } -bool PepperScrollbarWidget::OnKeyDown(const NPPepperEvent& event) { - bool rv = true; - int key = event.u.key.normalizedKeyCode; - if ((vertical_ && key == base::VKEY_UP) || - (!vertical_ && key == base::VKEY_LEFT)) { - Scroll(true, SCROLL_BY_LINE, 0); - } else if ((vertical_ && key == base::VKEY_DOWN) || - (!vertical_ && key == base::VKEY_RIGHT)) { - Scroll(false, SCROLL_BY_LINE, 0); - } else if (key == base::VKEY_HOME) { - Scroll(true, SCROLL_BY_DOCUMENT, 0); - } else if (key == base::VKEY_END) { - Scroll(false, SCROLL_BY_DOCUMENT, 0); - } else if (key == base::VKEY_PRIOR) { - Scroll(true, SCROLL_BY_PAGE, 0); - } else if (key == base::VKEY_NEXT) { - Scroll(false, SCROLL_BY_PAGE, 0); +void PepperScrollbarWidget::getTickmarks(WebKit::WebScrollbar*, + WebVector<WebRect>* tickmarks) const { + if (tickmarks_.empty()) { + WebRect* rects = NULL; + tickmarks->assign(rects, 0); } else { - rv = false; + tickmarks->assign(&tickmarks_[0], tickmarks_.size()); } - - return rv; } -bool PepperScrollbarWidget::OnKeyUp(const NPPepperEvent& event) { - return false; -} - -int PepperScrollbarWidget::HitTest(const gfx::Point& location) const { - if (BackArrowRect().Contains(location)) { - return vertical_ ? UP_ARROW : LEFT_ARROW; - } else if (ForwardArrowRect().Contains(location)) { - return vertical_ ? DOWN_ARROW : RIGHT_ARROW; - } else if (ThumbRect().Contains(location)) { - return vertical_ ? VERTICAL_THUMB : HORIZONTAL_THUMB; - } else if (BackTrackRect().Contains(location)) { - return vertical_ ? VERTICAL_TRACK : HORIZONTAL_TRACK; - } else if (ForwardTrackRect().Contains(location)) { - return vertical_ ? VERTICAL_TRACK : HORIZONTAL_TRACK; - } - - return -1; -} - -int PepperScrollbarWidget::ThumbPosition(const gfx::Point& location) const { - int position; - if (vertical_) { - position = location.y() - location_.y() - arrow_length_; - } else { - position = location.x() - location_.x() - arrow_length_; - } - - return position; -} - -void PepperScrollbarWidget::MoveThumb(int new_position) { - float delta = static_cast<float>(new_position - pressed_position_); - if (delta > MaximumThumbPosition() - thumb_position_) { - // Don't want to go beyond max pos. - delta = MaximumThumbPosition() - thumb_position_; - } else if (delta < -1 * thumb_position_) { - // Don't want to go below 0. - delta = - 1 * thumb_position_; - } - - SetPosition(thumb_position_ + delta, true); -} - -void PepperScrollbarWidget::SetPosition(float position, bool notify_client) { - float old_thumb_position = thumb_position_; - thumb_position_ = position; - if (IsThumb(pressed_part_)) { - pressed_position_ = - pressed_position_ + static_cast<int>(position - old_thumb_position); - } - - if (notify_client) - WidgetPropertyChanged(NPWidgetPropertyScrollbarPosition); - - dirty_rect_ = dirty_rect_.Union(gfx::Rect( - location_, - gfx::Size(vertical_ ? thickness_: length_, - vertical_ ? length_ : thickness_))); - WidgetPropertyChanged(NPWidgetPropertyDirtyRect); -} - -void PepperScrollbarWidget::OnTimerFired() { - AutoScroll(kAutoscrollTimerDelay); -} - -void PepperScrollbarWidget::AutoScroll(float delay) { - if (pressed_part_ == -1 || IsThumb(pressed_part_)) { - NOTREACHED(); - return; - } - - if (DidThumbCatchUpWithMouse()) - return; - - ScrollGranularity granularity = - IsArrow(pressed_part_) ? SCROLL_BY_LINE : SCROLL_BY_PAGE; - Scroll(IsBackscrolling(), granularity, 0); - - StartTimerIfNeeded(delay); -} - -void PepperScrollbarWidget::Scroll(bool backwards, - ScrollGranularity granularity, - int pixels) { - float new_position; - if (granularity == SCROLL_BY_LINE || granularity == SCROLL_BY_PAGE) { - int delta = - granularity == SCROLL_BY_LINE ? kPixelsPerLine : pixels_per_page_; - if (backwards) - delta *= -1; - - // delta is in document pixels. We want to convert to scrollbar pixels. - new_position = thumb_position_ + ThumbPixelsFromDocumentPixels(delta); - } else if (granularity == SCROLL_BY_PIXELS) { - if (backwards) - pixels *= -1; - new_position = thumb_position_ + ThumbPixelsFromDocumentPixels(pixels); - } else { - DCHECK(granularity == SCROLL_BY_DOCUMENT); - new_position = - backwards ? 0.0f : static_cast<float>(MaximumThumbPosition()); - } - - SetPosition(std::max<float>(std::min<float>( - new_position, static_cast<float>(MaximumThumbPosition())), 0.0), true); -} - -void PepperScrollbarWidget::ScrollTo(int position) { - if (position > (total_length_ - length_)) - position = total_length_ - length_; - float thumb_position = - static_cast<float>(position) * MaximumThumbPosition() / - (total_length_ - length_); - SetPosition(thumb_position, false); -} - -void PepperScrollbarWidget::StartTimerIfNeeded(float delay) { - if (IsThumb(pressed_part_)) - return; - - if (DidThumbCatchUpWithMouse()) - return; - - if (IsBackscrolling()) { - if (thumb_position_ == 0) - return; // Already at beginning. - } else { - if (static_cast<int>(thumb_position_) == MaximumThumbPosition()) - return; // Already at end. - } - - DCHECK(!timer_.IsRunning()); - timer_.Start( - base::TimeDelta::FromMilliseconds(static_cast<int64>(1000 * delay)), - this, - &PepperScrollbarWidget::OnTimerFired); -} - -void PepperScrollbarWidget::StopTimerIfNeeded() { - if (!timer_.IsRunning()) - return; - - timer_.Stop(); -} - -gfx::Rect PepperScrollbarWidget::BackArrowRect() const { - int width = vertical_ ? thickness_ : arrow_length_; - int height = vertical_ ? arrow_length_ : thickness_; - return gfx::Rect(location_.x(), location_.y(), width, height); -} - -gfx::Rect PepperScrollbarWidget::ForwardArrowRect() const { - int x = location_.x(); - int y = location_.y(); - if (vertical_) { - y += length_ - arrow_length_; - } else { - x += length_ - arrow_length_; - } - int width = vertical_ ? thickness_ : arrow_length_; - int height = vertical_ ? arrow_length_ : thickness_; - return gfx::Rect(x, y, width, height); -} - -gfx::Rect PepperScrollbarWidget::BackTrackRect() const { - int x = location_.x(); - int y = location_.y(); - if (vertical_) { - y += arrow_length_; - } else { - x += arrow_length_; - } - int length = static_cast<int>(thumb_position_) + ThumbLength() / 2; - int width = vertical_ ? thickness_ : length; - int height = vertical_ ? length : thickness_; - return gfx::Rect(x, y, width, height); -} - -gfx::Rect PepperScrollbarWidget::ForwardTrackRect() const { - int track_begin_offset = - arrow_length_ + static_cast<int>(thumb_position_) + ThumbLength() / 2; - int track_length = - TrackLength() - ThumbLength() / 2 - static_cast<int>(thumb_position_); - int x = location_.x(); - int y = location_.y(); - if (vertical_) { - y += track_begin_offset; - } else { - x += track_begin_offset; - } - int width = vertical_ ? thickness_ : track_length; - int height = vertical_ ? track_length : thickness_; - return gfx::Rect(x, y, width, height); -} - -gfx::Rect PepperScrollbarWidget::TrackRect() const { - int x = location_.x(); - int y = location_.y(); - if (vertical_) { - y += arrow_length_; - } else { - x += arrow_length_; - } - int width = vertical_ ? thickness_ : TrackLength(); - int height = vertical_ ? TrackLength() : thickness_; - return gfx::Rect(x, y, width, height); -} - -gfx::Rect PepperScrollbarWidget::ThumbRect() const { - int thumb_begin_offset = arrow_length_ + static_cast<int>(thumb_position_); - int x = location_.x(); - int y = location_.y(); - if (vertical_) { - y += thumb_begin_offset; - } else { - x += thumb_begin_offset; - } - int width = vertical_ ? thickness_ : ThumbLength(); - int height = vertical_ ? ThumbLength() : thickness_; - return gfx::Rect(x, y, width, height); -} - -bool PepperScrollbarWidget::IsBackTrackPressed() const { - return pressed_position_ >= 0 && - pressed_position_ < static_cast<int>(thumb_position_); -} - -bool PepperScrollbarWidget::DidThumbCatchUpWithMouse() { - if (IsTrackbar(pressed_part_) && IsThumbUnderMouse()) { - hovered_part_ = vertical_ ? - VERTICAL_THUMB : HORIZONTAL_THUMB; - return true; - } - - return false; -} - -bool PepperScrollbarWidget::IsThumbUnderMouse() const { - int thumb_start = static_cast<int>(thumb_position_); - int thumb_end = thumb_start + ThumbLength(); - return pressed_position_ >= thumb_start && - pressed_position_ < thumb_end; -} - -bool PepperScrollbarWidget::IsBackscrolling() const { - return pressed_part_ == UP_ARROW || - pressed_part_ == LEFT_ARROW || - ((pressed_part_ == VERTICAL_TRACK || - pressed_part_ == HORIZONTAL_TRACK) && - IsBackTrackPressed()); -} - -int PepperScrollbarWidget::TrackLength() const { - int rv = length_ - 2 * arrow_length_; - if (rv < 0) - rv = 0; // In case there isn't space after we draw the arrows. - return rv; -} - -int PepperScrollbarWidget::ThumbLength() const { - float proportion = static_cast<float>(length_) / total_length_; - int track_length = TrackLength(); - int length = static_cast<int>(proportion * track_length); - length = std::max(length, MinimumThumbLength()); - if (length > track_length) - length = 0; // In case there's no space for the thumb. - return length; -} - -int PepperScrollbarWidget::MaximumThumbPosition() const { - return TrackLength() - ThumbLength(); -} - -float PepperScrollbarWidget::ThumbPixelsFromDocumentPixels(int pixels) const { - return static_cast<float>(pixels) * MaximumThumbPosition() / - (total_length_ - length_); -} - -bool PepperScrollbarWidget::IsArrow(int part) { - return part == DOWN_ARROW || - part == LEFT_ARROW || - part == RIGHT_ARROW || - part == UP_ARROW; -} - -bool PepperScrollbarWidget::IsTrackbar(int part) { - return part == HORIZONTAL_TRACK || part == VERTICAL_TRACK; -} - -bool PepperScrollbarWidget::IsThumb(int part) { - return part == HORIZONTAL_THUMB || part == VERTICAL_THUMB; +void PepperScrollbarWidget::NotifyInvalidate() { + if (!dirty_rect_.IsEmpty()) + WidgetPropertyChanged(NPWidgetPropertyDirtyRect); } diff --git a/chrome/renderer/pepper_scrollbar_widget.h b/chrome/renderer/pepper_scrollbar_widget.h index 9d37fdb..d04ef14 100644 --- a/chrome/renderer/pepper_scrollbar_widget.h +++ b/chrome/renderer/pepper_scrollbar_widget.h @@ -5,26 +5,38 @@ #ifndef CHROME_RENDERER_PEPPER_SCROLLBAR_WIDGET_H_ #define CHROME_RENDERER_PEPPER_SCROLLBAR_WIDGET_H_ -#include "base/timer.h" +#include <vector> + +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "build/build_config.h" #include "gfx/point.h" #include "gfx/rect.h" #include "chrome/renderer/pepper_widget.h" +#include "third_party/WebKit/WebKit/chromium/public/WebRect.h" +#include "third_party/WebKit/WebKit/chromium/public/WebScrollBarClient.h" // An implementation of a horizontal/vertical scrollbar. -// TODO(jam): this code is copied from WebKit/Chromium, use WebCore::Scrollbar -// instead. -class PepperScrollbarWidget : public PepperWidget { +class PepperScrollbarWidget : public PepperWidget, + public WebKit::WebScrollbarClient, + public base::RefCounted<PepperScrollbarWidget> { public: - PepperScrollbarWidget(const NPScrollbarCreateParams& params); - ~PepperScrollbarWidget(); + explicit PepperScrollbarWidget(const NPScrollbarCreateParams& params); + // PepperWidget virtual void Destroy(); virtual void Paint(Graphics2DDeviceContext* context, const NPRect& dirty); virtual bool HandleEvent(const NPPepperEvent& event); virtual void GetProperty(NPWidgetProperty property, void* value); virtual void SetProperty(NPWidgetProperty property, void* value); + // WebKit::WebScrollbarClient + virtual void valueChanged(WebKit::WebScrollbar*); + virtual void invalidateScrollbarRect(WebKit::WebScrollbar*, + const WebKit::WebRect&); + virtual void getTickmarks(WebKit::WebScrollbar*, + WebKit::WebVector<WebKit::WebRect>*) const; + #if defined(OS_LINUX) static void SetScrollbarColors(unsigned inactive_color, unsigned active_color, @@ -32,188 +44,16 @@ class PepperScrollbarWidget : public PepperWidget { #endif private: - enum ScrollGranularity { - SCROLL_BY_LINE, - SCROLL_BY_PAGE, - SCROLL_BY_DOCUMENT, - SCROLL_BY_PIXELS, - }; - - enum Part { - DOWN_ARROW, - LEFT_ARROW, - RIGHT_ARROW, - UP_ARROW, - HORIZONTAL_THUMB, - VERTICAL_THUMB, - HORIZONTAL_TRACK, - VERTICAL_TRACK, - }; - -#if defined(OS_WIN) - int GetThemeState(Part part) const; - int GetThemeArrowState(Part part) const; - int GetClassicThemeState(Part part) const; - bool IsVistaOrNewer() const; -#endif - - // Length is the size in pixels of the scroll bar, while total_length is the - // length of the scrollable document. - void SetLocation(const gfx::Point& location, int length, int total_length); - gfx::Rect GetLocation() const; - - // Returns the offset into the scrollbar document. - int GetPosition() const; - - // Called when the timer is fired. - void OnTimerFired(); - - // Scroll the document by the given amount. pixels is only used when the - // granularity is SCROLL_BY_PIXELS. - void Scroll(bool backwards, ScrollGranularity granularity, int pixels); - - // Scroll to the given location in document pixels. - void ScrollTo(int position); - - // Calculate one-time measurements on the components of the scroll bar. - void GenerateMeasurements(); - - // Mouse/keyboard event handlers. - bool OnMouseDown(const NPPepperEvent& event); - bool OnMouseUp(const NPPepperEvent& event); - bool OnMouseMove(const NPPepperEvent& event); - bool OnMouseLeave(const NPPepperEvent& event); - bool OnMouseWheel(const NPPepperEvent& event); - bool OnKeyDown(const NPPepperEvent& event); - bool OnKeyUp(const NPPepperEvent& event); - - // If the given location is over a part, return its id, otherwise -1. - int HitTest(const gfx::Point& location) const; - - // When dragging the thumb, on some platforms if the user moves the mouse too - // far then the thumb snaps back to its original location. - bool ShouldSnapBack(const gfx::Point& location) const; - - // Returns true if we should center the thumb on the track. - bool ShouldCenterOnThumb(const NPPepperEvent& event) const; - - // Given a coordinate, returns the position as an offset from the beginning of - // the track. - int ThumbPosition(const gfx::Point& location) const; - - // Moves the thumb and sets its location to the given position. - void MoveThumb(int new_position); - - // Sets the position and optionally calls the client to inform them of a new - // position. - void SetPosition(float position, bool notify_client); - - // Handle scrolling when the mouse is pressed over the track/arrow. - void AutoScroll(float delay); - - // If the mouse is pressed over an arrow or track area, starts a timer so that - // we scroll another time. - void StartTimerIfNeeded(float delay); + friend class base::RefCounted<PepperScrollbarWidget>; - // Cancel the timer if it's running. - void StopTimerIfNeeded(); - - // Getters for location and size of arrows, thumb, and track. - gfx::Rect BackArrowRect() const; // Up/left arrow. - gfx::Rect ForwardArrowRect() const; // Down/right arrow. - gfx::Rect BackTrackRect() const; // Track before the thumb. - gfx::Rect ForwardTrackRect() const; // Track after the thumb. - gfx::Rect TrackRect() const; // Entire track. - gfx::Rect ThumbRect() const; // Thumb. - - // Returns true if the back part of the track is pressed. Returning false - // does not necessarily mean the forward part is pressed. - bool IsBackTrackPressed() const; - - // Returns true if the the trackbar was pressed and the thumb has moved enough - // that it's now over the pressed position. - bool DidThumbCatchUpWithMouse(); - - // Returns true if the thumb is under the mouse. - bool IsThumbUnderMouse() const; - - // Returns true if the up/left/back track are pressed. - bool IsBackscrolling() const; - - // How many pixels is the track length (i.e. without the arrows). - int TrackLength() const; - - // The length of the thumb in pixels. - int ThumbLength() const; - - // Minimium number of pixels for the thumb. - int MinimumThumbLength() const; - - // Maximum offst of the thumb in pixels from the beginning of the track. - int MaximumThumbPosition() const; - - // Converts between pixels in the document to pixels of the thumb position. - float ThumbPixelsFromDocumentPixels(int pixels) const; - - // Helpers for mapping between theme part IDs and their functionality. - static bool IsArrow(int part); - static bool IsTrackbar(int part); - static bool IsThumb(int part); - - bool vertical_; - bool enabled_; - gfx::Point location_; - // Length of the scroll bar. - int length_; - // Length of the document being scrolled. - int total_length_; - // Calculated value, based on the length of the scrollbar and document, of how - // many pixels to advance when the user clicks on the trackbar. - int pixels_per_page_; - - // Values we calculated on construction. - // How wide/high a vertical/horizontal scrollbar is. - int thickness_; - int arrow_length_; - - // -1 if no parts are hovered or pressed. Otherwise a value from Part. - int hovered_part_; - int pressed_part_; - - // How many pixels from the beginning of the track the thumb starts. - // This is a float because in case of a very large document, clicking the - // arrow button might not be enough to advance the thumb by one pixel. If - // this was an int, then clicking it repeatedly wouldn't move the thumb. - float thumb_position_; - - // True if we have mouse capture. - bool have_mouse_capture_; - // If we have mouse capture and the user clicked on a trackbar, where they - // started their click relative to the beginning of the track. - float drag_origin_; - // The current offset relative to the beginning of the track of the last - // mouse down. drag_origin_ isn't enough because when the user is dragging - // the thumb, we get events even when they stop moving the mouse, and so we - // need to know if the mouse moved since the last time that we moved the - // thumb. - int pressed_position_; + ~PepperScrollbarWidget(); - // Used when holding down arrows or tracks. - base::OneShotTimer<PepperScrollbarWidget> timer_; + void NotifyInvalidate(); gfx::Rect dirty_rect_; - - // How many pixels to advance in the document when pressing the arrows. - static const int kPixelsPerLine; - - // Used to calculate how many pixels to advance in the document when clicking - // the trackbar. - static const int kMaxOverlapBetweenPages; - static const float kMinFractionToStepWhenPaging; - - // Used when holding down arrows/track. - static const float kInitialAutoscrollTimerDelay; - static const float kAutoscrollTimerDelay; + gfx::Rect location_; + std::vector<WebKit::WebRect> tickmarks_; + scoped_ptr<WebKit::WebScrollbar> scrollbar_; DISALLOW_COPY_AND_ASSIGN(PepperScrollbarWidget); }; diff --git a/chrome/renderer/pepper_scrollbar_widget_linux.cc b/chrome/renderer/pepper_scrollbar_widget_linux.cc deleted file mode 100644 index 3468383..0000000 --- a/chrome/renderer/pepper_scrollbar_widget_linux.cc +++ /dev/null @@ -1,244 +0,0 @@ -// Copyright (c) 2010 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 "chrome/renderer/pepper_scrollbar_widget.h" - -#include "base/logging.h" -#include "chrome/renderer/pepper_devices.h" -#include "skia/ext/platform_canvas.h" - -namespace { - -unsigned int g_scrollbar_width = 15; -unsigned int g_thumb_inactive_color = 0xf0ebe5; -unsigned int g_thumb_active_color = 0xfaf8f5; -unsigned int g_track_color = 0xe3ddd8; - -SkScalar Clamp(SkScalar value, - SkScalar min, - SkScalar max) { - return std::min(std::max(value, min), max); -} - -SkColor SaturateAndBrighten(SkScalar* hsv, - SkScalar saturate_amount, - SkScalar brighten_amount) { - SkScalar color[3]; - color[0] = hsv[0]; - color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0); - color[2] = Clamp(hsv[2] + brighten_amount, 0.0, 1.0); - return SkHSVToColor(color); -} - -SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) { - // GTK Theme engines have way too much control over the layout of - // the scrollbar. We might be able to more closely approximate its - // look-and-feel, if we sent whole images instead of just colors - // from the browser to the renderer. But even then, some themes - // would just break. - // - // So, instead, we don't even try to 100% replicate the look of - // the native scrollbar. We render our own version, but we make - // sure to pick colors that blend in nicely with the system GTK - // theme. In most cases, we can just sample a couple of pixels - // from the system scrollbar and use those colors to draw our - // scrollbar. - // - // This works fine for the track color and the overall thumb - // color. But it fails spectacularly for the outline color used - // around the thumb piece. Not all themes have a clearly defined - // outline. For some of them it is partially transparent, and for - // others the thickness is very unpredictable. - // - // So, instead of trying to approximate the system theme, we - // instead try to compute a reasonable looking choice based on the - // known color of the track and the thumb piece. This is difficult - // when trying to deal both with high- and low-contrast themes, - // and both with positive and inverted themes. - // - // The following code has been tested to look OK with all of the - // default GTK themes. - SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2, 0.2, 0.5); - SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5); - - if (hsv1[2] + hsv2[2] > 1.0) - diff = -diff; - - return SaturateAndBrighten(hsv2, -0.2, diff); -} - - -void DrawVertLine(SkCanvas* canvas, - int x, - int y1, - int y2, - const SkPaint& paint) { - SkIRect skrect; - skrect.set(x, y1, x + 1, y2 + 1); - canvas->drawIRect(skrect, paint); -} - -void DrawHorizLine(SkCanvas* canvas, - int x1, - int x2, - int y, - const SkPaint& paint) { - SkIRect skrect; - skrect.set(x1, y, x2 + 1, y + 1); - canvas->drawIRect(skrect, paint); -} - -void DrawBox(SkCanvas* canvas, - const gfx::Rect& rect, - const SkPaint& paint) { - const int right = rect.x() + rect.width() - 1; - const int bottom = rect.y() + rect.height() - 1; - DrawHorizLine(canvas, rect.x(), right, rect.y(), paint); - DrawVertLine(canvas, right, rect.y(), bottom, paint); - DrawHorizLine(canvas, rect.x(), right, bottom, paint); - DrawVertLine(canvas, rect.x(), rect.y(), bottom, paint); -} - -void PaintTrack(skia::PlatformCanvas* canvas, - const gfx::Rect& rect) { - SkPaint paint; - SkIRect skrect; - - skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); - SkScalar track_hsv[3]; - SkColorToHSV(g_track_color, track_hsv); - paint.setColor(SaturateAndBrighten(track_hsv, 0, 0)); - canvas->drawIRect(skrect, paint); - - SkScalar thumb_hsv[3]; - SkColorToHSV(g_thumb_inactive_color, thumb_hsv); - - paint.setColor(OutlineColor(track_hsv, thumb_hsv)); - DrawBox(canvas, rect, paint); -} - -void PaintThumb(skia::PlatformCanvas* canvas, - bool vertical, - bool hovered, - const gfx::Rect& rect) { - const int midx = rect.x() + rect.width() / 2; - const int midy = rect.y() + rect.height() / 2; - - SkScalar thumb[3]; - SkColorToHSV(hovered ? g_thumb_active_color : g_thumb_inactive_color, thumb); - - SkPaint paint; - paint.setColor(SaturateAndBrighten(thumb, 0, 0.02)); - - SkIRect skrect; - if (vertical) - skrect.set(rect.x(), rect.y(), midx + 1, rect.y() + rect.height()); - else - skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), midy + 1); - - canvas->drawIRect(skrect, paint); - - paint.setColor(SaturateAndBrighten(thumb, 0, -0.02)); - - if (vertical) { - skrect.set( - midx + 1, rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); - } else { - skrect.set( - rect.x(), midy + 1, rect.x() + rect.width(), rect.y() + rect.height()); - } - - canvas->drawIRect(skrect, paint); - - SkScalar track[3]; - SkColorToHSV(g_track_color, track); - paint.setColor(OutlineColor(track, thumb)); - DrawBox(canvas, rect, paint); - - if (rect.height() > 10 && rect.width() > 10) { - const int grippy_half_width = 2; - const int inter_grippy_offset = 3; - if (vertical) { - DrawHorizLine(canvas, - midx - grippy_half_width, - midx + grippy_half_width, - midy - inter_grippy_offset, - paint); - DrawHorizLine(canvas, - midx - grippy_half_width, - midx + grippy_half_width, - midy, - paint); - DrawHorizLine(canvas, - midx - grippy_half_width, - midx + grippy_half_width, - midy + inter_grippy_offset, - paint); - } else { - DrawVertLine(canvas, - midx - inter_grippy_offset, - midy - grippy_half_width, - midy + grippy_half_width, - paint); - DrawVertLine(canvas, - midx, - midy - grippy_half_width, - midy + grippy_half_width, - paint); - DrawVertLine(canvas, - midx + inter_grippy_offset, - midy - grippy_half_width, - midy + grippy_half_width, - paint); - } - } -} - - -} // annonymous namespace - -void PepperScrollbarWidget::Paint(Graphics2DDeviceContext* context, - const NPRect& dirty) { - skia::PlatformCanvas* canvas = context->canvas(); - - // Beginning track. - PaintTrack(canvas, BackTrackRect()); - - // End track. - PaintTrack(canvas, ForwardTrackRect()); - - // Thumb. - PaintThumb(canvas, vertical_, IsThumb(hovered_part_), ThumbRect()); - - canvas->endPlatformPaint(); -} - -void PepperScrollbarWidget::GenerateMeasurements() { - // TODO(port) - thickness_ = g_scrollbar_width; - arrow_length_ = 0; // On Linux, we don't use buttons. -} - -bool PepperScrollbarWidget::ShouldSnapBack(const gfx::Point& location) const { - return false; -} - -bool PepperScrollbarWidget::ShouldCenterOnThumb( - const NPPepperEvent& event) const { - return (event.u.mouse.button == NPMouseButton_Left && - event.u.mouse.modifier & NPEventModifier_ShiftKey) || - event.u.mouse.button == NPMouseButton_Middle; -} - -void PepperScrollbarWidget::SetScrollbarColors(unsigned inactive_color, - unsigned active_color, - unsigned track_color) { - g_thumb_inactive_color = inactive_color; - g_thumb_active_color = active_color; - g_track_color = track_color; -} - -int PepperScrollbarWidget::MinimumThumbLength() const { - return 2 * g_scrollbar_width; // This matches Firefox on Linux. -} diff --git a/chrome/renderer/pepper_scrollbar_widget_mac.mm b/chrome/renderer/pepper_scrollbar_widget_mac.mm deleted file mode 100644 index 0e73ab6..0000000 --- a/chrome/renderer/pepper_scrollbar_widget_mac.mm +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2010 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 "chrome/renderer/pepper_scrollbar_widget.h" - -const int PepperScrollbarWidget::kMaxOverlapBetweenPages = 40; - -void PepperScrollbarWidget::Paint(Graphics2DDeviceContext* context, - const NPRect& dirty) { - // TODO(port) -} - -void PepperScrollbarWidget::GenerateMeasurements() { - // TODO(port) - thickness_ = 0; - arrow_length_ = 0; -} - -bool PepperScrollbarWidget::ShouldSnapBack(const gfx::Point& location) const { - return false; -} - -bool PepperScrollbarWidget::ShouldCenterOnThumb( - const NPPepperEvent& event) const { - // TODO: to do this properly on Mac, the AppleScrollerPagingBehavior - // preference needs to be checked. See ScrollbarThemeChromiumMac.mm. - return event.u.mouse.button == NPMouseButton_Left && - event.u.mouse.modifier & NPEventModifier_AltKey; -} - -int PepperScrollbarWidget::MinimumThumbLength() const { - return thickness_; -} diff --git a/chrome/renderer/pepper_scrollbar_widget_win.cc b/chrome/renderer/pepper_scrollbar_widget_win.cc deleted file mode 100644 index ddfdcf1..0000000 --- a/chrome/renderer/pepper_scrollbar_widget_win.cc +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright (c) 2010 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 <vsstyle.h> - -#include "chrome/renderer/pepper_scrollbar_widget.h" - -#include "base/logging.h" -#include "base/win_util.h" -#include "gfx/native_theme_win.h" -#include "chrome/renderer/pepper_devices.h" -#include "skia/ext/platform_canvas.h" -#include "skia/ext/platform_device.h" - - -void PepperScrollbarWidget::Paint(Graphics2DDeviceContext* context, - const NPRect& dirty) { - skia::PlatformCanvas* canvas = context->canvas(); - HDC dc = canvas->beginPlatformPaint(); - - Part part; - int part_id; - - // Up/Left arrow. - part = vertical_ ? UP_ARROW : LEFT_ARROW; - part_id = vertical_ ? DFCS_SCROLLUP : DFCS_SCROLLLEFT; - gfx::NativeTheme::instance()->PaintScrollbarArrow( - dc, GetThemeArrowState(part), part_id | GetClassicThemeState(part), - &BackArrowRect().ToRECT()); - - // Down/Right arrow. - part = vertical_ ? DOWN_ARROW : RIGHT_ARROW; - part_id = vertical_ ? DFCS_SCROLLDOWN : DFCS_SCROLLRIGHT; - gfx::NativeTheme::instance()->PaintScrollbarArrow( - dc, GetThemeArrowState(part), part_id | GetClassicThemeState(part), - &ForwardArrowRect().ToRECT()); - - // Beginning track. - part = vertical_ ? VERTICAL_TRACK : HORIZONTAL_TRACK; - part_id = vertical_ ? SBP_UPPERTRACKVERT : SBP_UPPERTRACKHORZ; - gfx::Rect align_rect(location_, gfx::Size()); - gfx::NativeTheme::instance()->PaintScrollbarTrack( - dc, part_id, GetThemeState(part), GetClassicThemeState(part), - &BackTrackRect().ToRECT(), &align_rect.ToRECT(), canvas); - - // End track. - part_id = vertical_ ? SBP_LOWERTRACKVERT : SBP_LOWERTRACKHORZ; - gfx::NativeTheme::instance()->PaintScrollbarTrack( - dc, part_id, GetThemeState(part), GetClassicThemeState(part), - &ForwardTrackRect().ToRECT(), &align_rect.ToRECT(), canvas); - - // Thumb. - part = vertical_ ? VERTICAL_THUMB : HORIZONTAL_THUMB; - part_id = vertical_ ? SBP_THUMBBTNVERT : SBP_THUMBBTNHORZ; - gfx::NativeTheme::instance()->PaintScrollbarThumb( - dc, part_id, GetThemeState(part), GetClassicThemeState(part), - &ThumbRect().ToRECT()); - - // Gripper. - part_id = vertical_ ? SBP_GRIPPERVERT : SBP_GRIPPERHORZ; - gfx::NativeTheme::instance()->PaintScrollbarThumb( - dc, part_id, GetThemeState(part), GetClassicThemeState(part), - &ThumbRect().ToRECT()); - - if (gfx::NativeTheme::instance()->IsClassicTheme( - gfx::NativeTheme::SCROLLBAR)) { - // Make the pixels opaque for the themed controls to appear correctly. - canvas->getTopPlatformDevice().makeOpaque( - location_.x(), location_.y(), vertical_ ? thickness_ : length_, - vertical_ ? length_ : thickness_); - } - - canvas->endPlatformPaint(); -} - -int PepperScrollbarWidget::GetThemeState(Part part) const { - // When dragging the thumb, draw thumb pressed and other segments normal - // regardless of where the cursor actually is. See also four places in - // getThemeArrowState(). - if (IsThumb(pressed_part_)) { - if (IsThumb(part)) - return SCRBS_PRESSED; - return IsVistaOrNewer() ? SCRBS_HOVER : SCRBS_NORMAL; - } - if (!enabled_) - return SCRBS_DISABLED; - if (hovered_part_ != part || IsTrackbar(part)) { - return (hovered_part_ == -1 || !IsVistaOrNewer()) ? - SCRBS_NORMAL : SCRBS_HOVER; - } - if (pressed_part_ == -1) - return SCRBS_HOT; - return (pressed_part_ == part) ? SCRBS_PRESSED : SCRBS_NORMAL; -} - -int PepperScrollbarWidget::GetThemeArrowState(Part part) const { - if (part == LEFT_ARROW || part == UP_ARROW) { - if (!vertical_) { - if (IsThumb(pressed_part_)) - return !IsVistaOrNewer() ? ABS_LEFTNORMAL : ABS_LEFTHOVER; - if (!enabled_) - return ABS_LEFTDISABLED; - if (hovered_part_ != part) { - return ((hovered_part_ == -1) || !IsVistaOrNewer()) ? - ABS_LEFTNORMAL : ABS_LEFTHOVER; - } - if (pressed_part_ == -1) - return ABS_LEFTHOT; - return (pressed_part_ == part) ? ABS_LEFTPRESSED : ABS_LEFTNORMAL; - } - if (IsThumb(pressed_part_)) - return !IsVistaOrNewer() ? ABS_UPNORMAL : ABS_UPHOVER; - if (!enabled_) - return ABS_UPDISABLED; - if (hovered_part_ != part) { - return ((hovered_part_ == -1) || !IsVistaOrNewer()) ? - ABS_UPNORMAL : ABS_UPHOVER; - } - if (pressed_part_ == -1) - return ABS_UPHOT; - return (pressed_part_ == part) ? ABS_UPPRESSED : ABS_UPNORMAL; - } - if (!vertical_) { - if (IsThumb(pressed_part_)) - return !IsVistaOrNewer() ? ABS_RIGHTNORMAL : ABS_RIGHTHOVER; - if (!enabled_) - return ABS_RIGHTDISABLED; - if (hovered_part_ != part) { - return ((hovered_part_ == -1) || !IsVistaOrNewer()) ? - ABS_RIGHTNORMAL : ABS_RIGHTHOVER; - } - if (pressed_part_ == -1) - return ABS_RIGHTHOT; - return (pressed_part_ == part) ? ABS_RIGHTPRESSED : ABS_RIGHTNORMAL; - } - if (IsThumb(pressed_part_)) - return !IsVistaOrNewer() ? ABS_DOWNNORMAL : ABS_DOWNHOVER; - if (!enabled_) - return ABS_DOWNDISABLED; - if (hovered_part_ != part) { - return ((hovered_part_ == -1) || !IsVistaOrNewer()) ? - ABS_DOWNNORMAL : ABS_DOWNHOVER; - } - if (pressed_part_ == -1) - return ABS_DOWNHOT; - return (pressed_part_ == part) ? ABS_DOWNPRESSED : ABS_DOWNNORMAL; -} - -int PepperScrollbarWidget::GetClassicThemeState(Part part) const { - // When dragging the thumb, draw the buttons normal even when hovered. - if (IsThumb(pressed_part_)) - return 0; - if (!enabled_) - return DFCS_INACTIVE; - if (hovered_part_ != part || IsTrackbar(part)) - return 0; - if (pressed_part_ == -1) - return DFCS_HOT; - return (pressed_part_ == part) ? (DFCS_PUSHED | DFCS_FLAT) : 0; -} - -bool PepperScrollbarWidget::IsVistaOrNewer() const { - return win_util::GetWinVersion() >= win_util::WINVERSION_VISTA; -} - -void PepperScrollbarWidget::GenerateMeasurements() { - thickness_ = GetSystemMetrics(SM_CXVSCROLL); - arrow_length_ = GetSystemMetrics(SM_CYVSCROLL); -} - -bool PepperScrollbarWidget::ShouldSnapBack(const gfx::Point& location) const { - static const int kOffEndMultiplier = 3; - static const int kOffSideMultiplier = 8; - - // Find the rect within which we shouldn't snap, by expanding the track rect - // in both dimensions. - gfx::Rect rect = TrackRect(); - int x_diff = - (vertical_ ? kOffSideMultiplier : kOffEndMultiplier) * thickness_; - int y_diff = - (vertical_ ? kOffEndMultiplier : kOffSideMultiplier) * thickness_; - rect.set_x(rect.x() - x_diff); - rect.set_width(rect.width() + 2 * x_diff); - rect.set_y(rect.y() - y_diff); - rect.set_height(rect.height() + 2 * y_diff); - - return !rect.Contains(location); -} - -bool PepperScrollbarWidget::ShouldCenterOnThumb( - const NPPepperEvent& event) const { - return event.u.mouse.button == NPMouseButton_Left && - event.u.mouse.modifier & NPEventModifier_ShiftKey; -} - -int PepperScrollbarWidget::MinimumThumbLength() const { - return thickness_; -} diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 4671156..411989c 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -49,7 +49,6 @@ #include "chrome/renderer/media/ipc_video_renderer.h" #include "chrome/renderer/navigation_state.h" #include "chrome/renderer/notification_provider.h" -#include "chrome/renderer/pepper_scrollbar_widget.h" #include "chrome/renderer/plugin_channel_host.h" #include "chrome/renderer/print_web_view_helper.h" #include "chrome/renderer/render_process.h" @@ -3880,11 +3879,6 @@ void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); - PepperScrollbarWidget::SetScrollbarColors( - renderer_prefs.thumb_inactive_color, - renderer_prefs.thumb_active_color, - renderer_prefs.track_color); - if (webview()) { webview()->setScrollbarColors( renderer_prefs.thumb_inactive_color, @@ -3926,8 +3920,8 @@ void RenderView::OnGetAccessibilityTree() { if (accessibility_.get()) { accessibility_->clear(); } - accessibility_.reset(WebAccessibilityCache::create()); - accessibility_->initialize(webview()); + accessibility_.reset(WebAccessibilityCache::create()); + accessibility_->initialize(webview()); WebAccessibilityObject src_tree = webview()->accessibilityObject(); webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get()); |