| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VIEWS_CONTROLS_RESIZE_GRIPPER_H_ | 5 #ifndef VIEWS_CONTROLS_RESIZE_AREA_H_ |
| 6 #define VIEWS_CONTROLS_RESIZE_GRIPPER_H_ | 6 #define VIEWS_CONTROLS_RESIZE_AREA_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "views/controls/image_view.h" | 10 #include "views/view.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 | 13 |
| 14 //////////////////////////////////////////////////////////////////////////////// | 14 //////////////////////////////////////////////////////////////////////////////// |
| 15 // | 15 // |
| 16 // A simple resize gripper (two vertical bars). | 16 // An invisible area that acts like a horizontal resizer. |
| 17 // | 17 // |
| 18 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 19 class ResizeGripper : public ImageView { | 19 class ResizeArea : public View { |
| 20 public: | 20 public: |
| 21 ////////////////////////////////////////////////////////////////////////////// | 21 ////////////////////////////////////////////////////////////////////////////// |
| 22 // | 22 // |
| 23 // The interface needed for getting notified about the resize event. | 23 // The interface needed for getting notified about the resize event. |
| 24 // | 24 // |
| 25 ////////////////////////////////////////////////////////////////////////////// | 25 ////////////////////////////////////////////////////////////////////////////// |
| 26 class ResizeGripperDelegate { | 26 class ResizeAreaDelegate { |
| 27 public: | 27 public: |
| 28 // OnResize is sent when resizing is detected. |resize_amount| specifies the | 28 // OnResize is sent when resizing is detected. |resize_amount| specifies the |
| 29 // number of pixels that the user wants to resize by, and can be negative or | 29 // number of pixels that the user wants to resize by, and can be negative or |
| 30 // positive (depending on direction of dragging and flips according to | 30 // positive (depending on direction of dragging and flips according to |
| 31 // locale directionality: dragging to the left in LTR locales gives negative | 31 // locale directionality: dragging to the left in LTR locales gives negative |
| 32 // |resize_amount| but positive amount for RTL). |done_resizing| is true if | 32 // |resize_amount| but positive amount for RTL). |done_resizing| is true if |
| 33 // the user has released the mouse. | 33 // the user has released the mouse. |
| 34 virtual void OnResize(int resize_amount, bool done_resizing) = 0; | 34 virtual void OnResize(int resize_amount, bool done_resizing) = 0; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 static const char kViewClassName[]; | 37 static const char kViewClassName[]; |
| 38 | 38 |
| 39 explicit ResizeGripper(ResizeGripperDelegate* delegate); | 39 explicit ResizeArea(ResizeAreaDelegate* delegate); |
| 40 virtual ~ResizeGripper(); | 40 virtual ~ResizeArea(); |
| 41 | 41 |
| 42 // Overridden from views::View: | 42 // Overridden from views::View: |
| 43 virtual std::string GetClassName() const; | 43 virtual std::string GetClassName() const; |
| 44 virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, | 44 virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, |
| 45 const gfx::Point& p); | 45 const gfx::Point& p); |
| 46 virtual void OnMouseEntered(const views::MouseEvent& event); | |
| 47 virtual void OnMouseExited(const views::MouseEvent& event); | |
| 48 virtual bool OnMousePressed(const views::MouseEvent& event); | 46 virtual bool OnMousePressed(const views::MouseEvent& event); |
| 49 virtual bool OnMouseDragged(const views::MouseEvent& event); | 47 virtual bool OnMouseDragged(const views::MouseEvent& event); |
| 50 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); | 48 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); |
| 51 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); | 49 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); |
| 52 | 50 |
| 53 private: | 51 private: |
| 54 // Report the amount the user resized by to the delegate, accounting for | 52 // Report the amount the user resized by to the delegate, accounting for |
| 55 // directionality. | 53 // directionality. |
| 56 void ReportResizeAmount(int resize_amount, bool last_update); | 54 void ReportResizeAmount(int resize_amount, bool last_update); |
| 57 | 55 |
| 58 // Changes the visibility of the gripper. | |
| 59 void SetGripperVisible(bool visible); | |
| 60 | |
| 61 // The delegate to notify when we have updates. | 56 // The delegate to notify when we have updates. |
| 62 ResizeGripperDelegate* delegate_; | 57 ResizeAreaDelegate* delegate_; |
| 63 | 58 |
| 64 // The mouse position at start (in screen coordinates). | 59 // The mouse position at start (in screen coordinates). |
| 65 int initial_position_; | 60 int initial_position_; |
| 66 | 61 |
| 67 // Are we showing the resize gripper? We only show the resize gripper when | 62 DISALLOW_COPY_AND_ASSIGN(ResizeArea); |
| 68 // the mouse is over us. | |
| 69 bool gripper_visible_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(ResizeGripper); | |
| 72 }; | 63 }; |
| 73 | 64 |
| 74 } // namespace views | 65 } // namespace views |
| 75 | 66 |
| 76 #endif // VIEWS_CONTROLS_RESIZE_GRIPPER_H_ | 67 #endif // VIEWS_CONTROLS_RESIZE_AREA_H_ |
| OLD | NEW |