diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-22 20:34:19 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-22 20:34:19 +0000 |
commit | f7fdd2894ef51ee234882fa2457bb1f2a8895cbe (patch) | |
tree | 3131cc8e2b13ec63255a71e53a403cd5842d87c1 | |
parent | 82f869be7e46d94d8f1abe34ae540f90608235fe (diff) | |
download | chromium_src-f7fdd2894ef51ee234882fa2457bb1f2a8895cbe.zip chromium_src-f7fdd2894ef51ee234882fa2457bb1f2a8895cbe.tar.gz chromium_src-f7fdd2894ef51ee234882fa2457bb1f2a8895cbe.tar.bz2 |
Makes the extension resize gripper only visible when the mouse is over
it.
BUG=45750
TEST=see bug
Review URL: http://codereview.chromium.org/2800022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50515 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | views/controls/image_view.cc | 3 | ||||
-rw-r--r-- | views/controls/resize_gripper.cc | 32 | ||||
-rw-r--r-- | views/controls/resize_gripper.h | 15 |
3 files changed, 45 insertions, 5 deletions
diff --git a/views/controls/image_view.cc b/views/controls/image_view.cc index fe6ad38..bf6219b 100644 --- a/views/controls/image_view.cc +++ b/views/controls/image_view.cc @@ -103,6 +103,9 @@ gfx::Point ImageView::ComputeImageOrigin(const gfx::Size& image_size) const { void ImageView::Paint(gfx::Canvas* canvas) { View::Paint(canvas); + if (image_.empty()) + return; + gfx::Rect image_bounds(GetImageBounds()); if (image_bounds.IsEmpty()) return; diff --git a/views/controls/resize_gripper.cc b/views/controls/resize_gripper.cc index 4d6d93b..2de05c2 100644 --- a/views/controls/resize_gripper.cc +++ b/views/controls/resize_gripper.cc @@ -20,10 +20,15 @@ static HCURSOR g_resize_cursor = NULL; // ResizeGripper ResizeGripper::ResizeGripper(ResizeGripperDelegate* delegate) - : delegate_(delegate), initial_position_(0) { + : delegate_(delegate), + initial_position_(0), + gripper_visible_(false) { ResourceBundle &rb = ResourceBundle::GetSharedInstance(); SkBitmap* gripper_image = rb.GetBitmapNamed(IDR_RESIZE_GRIPPER); - SetImage(gripper_image); + // Explicitly set the image size so that the preferred size is fixed to that + // of the image. If we didn't do this the preferred size would change + // depending upon whether the gripper was visible. + SetImageSize(gfx::Size(gripper_image->width(), gripper_image->height())); } ResizeGripper::~ResizeGripper() { @@ -46,6 +51,14 @@ gfx::NativeCursor ResizeGripper::GetCursorForPoint(Event::EventType event_type, #endif } +void ResizeGripper::OnMouseEntered(const views::MouseEvent& event) { + SetGripperVisible(true); +} + +void ResizeGripper::OnMouseExited(const views::MouseEvent& event) { + SetGripperVisible(false); +} + bool ResizeGripper::OnMousePressed(const views::MouseEvent& event) { if (!event.IsOnlyLeftMouseButton()) return false; @@ -74,6 +87,7 @@ void ResizeGripper::OnMouseReleased(const views::MouseEvent& event, ReportResizeAmount(initial_position_, true); else ReportResizeAmount(event.x(), true); + SetGripperVisible(HitTest(event.location())); } bool ResizeGripper::GetAccessibleRole(AccessibilityTypes::Role* role) { @@ -92,4 +106,18 @@ void ResizeGripper::ReportResizeAmount(int resize_amount, bool last_update) { delegate_->OnResize(resize_amount, last_update); } +void ResizeGripper::SetGripperVisible(bool visible) { + if (visible == gripper_visible_) + return; + + gripper_visible_ = visible; + if (gripper_visible_) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + SkBitmap* gripper_image = rb.GetBitmapNamed(IDR_RESIZE_GRIPPER); + SetImage(gripper_image); + } else { + SetImage(NULL); + } +} + } // namespace views diff --git a/views/controls/resize_gripper.h b/views/controls/resize_gripper.h index cac32e2..4f3edbe 100644 --- a/views/controls/resize_gripper.h +++ b/views/controls/resize_gripper.h @@ -24,7 +24,7 @@ class ResizeGripper : public ImageView { // ////////////////////////////////////////////////////////////////////////////// class ResizeGripperDelegate { - public: + public: // OnResize is sent when resizing is detected. |resize_amount| specifies the // number of pixels that the user wants to resize by, and can be negative or // positive (depending on direction of dragging and flips according to @@ -34,6 +34,8 @@ class ResizeGripper : public ImageView { virtual void OnResize(int resize_amount, bool done_resizing) = 0; }; + static const char kViewClassName[]; + explicit ResizeGripper(ResizeGripperDelegate* delegate); virtual ~ResizeGripper(); @@ -41,24 +43,31 @@ class ResizeGripper : public ImageView { virtual std::string GetClassName() const; virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type, const gfx::Point& p); + virtual void OnMouseEntered(const views::MouseEvent& event); + virtual void OnMouseExited(const views::MouseEvent& event); virtual bool OnMousePressed(const views::MouseEvent& event); virtual bool OnMouseDragged(const views::MouseEvent& event); virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); - static const char kViewClassName[]; - private: // Report the amount the user resized by to the delegate, accounting for // directionality. void ReportResizeAmount(int resize_amount, bool last_update); + // Changes the visibility of the gripper. + void SetGripperVisible(bool visible); + // The delegate to notify when we have updates. ResizeGripperDelegate* delegate_; // The mouse position at start (in screen coordinates). int initial_position_; + // Are we showing the resize gripper? We only show the resize gripper when + // the mouse is over us. + bool gripper_visible_; + DISALLOW_COPY_AND_ASSIGN(ResizeGripper); }; |