1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ui/views/controls/scrollbar/base_scroll_bar_button.h" 6 7 #include "base/bind.h" 8 #include "base/bind_helpers.h" 9 #include "ui/gfx/screen.h" 10 11 namespace views { 12 BaseScrollBarButton(ButtonListener * listener)13BaseScrollBarButton::BaseScrollBarButton(ButtonListener* listener) 14 : CustomButton(listener), 15 repeater_(base::Bind(&BaseScrollBarButton::RepeaterNotifyClick, 16 base::Unretained(this))) { 17 } 18 ~BaseScrollBarButton()19BaseScrollBarButton::~BaseScrollBarButton() { 20 } 21 OnMousePressed(const ui::MouseEvent & event)22bool BaseScrollBarButton::OnMousePressed(const ui::MouseEvent& event) { 23 Button::NotifyClick(event); 24 repeater_.Start(); 25 return true; 26 } 27 OnMouseReleased(const ui::MouseEvent & event)28void BaseScrollBarButton::OnMouseReleased(const ui::MouseEvent& event) { 29 OnMouseCaptureLost(); 30 } 31 OnMouseCaptureLost()32void BaseScrollBarButton::OnMouseCaptureLost() { 33 repeater_.Stop(); 34 } 35 RepeaterNotifyClick()36void BaseScrollBarButton::RepeaterNotifyClick() { 37 // TODO(sky): See if we can convert to using |Screen| everywhere. 38 #if defined(OS_WIN) && !defined(USE_AURA) 39 gfx::Point cursor_point(GetMessagePos()); 40 #else 41 // TODO(scottmg): Native is wrong: http://crbug.com/133312 42 gfx::Point cursor_point = 43 gfx::Screen::GetNativeScreen()->GetCursorScreenPoint(); 44 #endif 45 ui::MouseEvent event(ui::ET_MOUSE_RELEASED, 46 cursor_point, cursor_point, 47 ui::EF_LEFT_MOUSE_BUTTON); 48 Button::NotifyClick(event); 49 } 50 51 } // namespace views 52