diff options
-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); }; |