summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/controls/resize_area.cc87
-rw-r--r--views/controls/resize_area.h (renamed from views/controls/resize_gripper.h)31
-rw-r--r--views/controls/resize_gripper.cc123
-rw-r--r--views/views.gyp4
4 files changed, 100 insertions, 145 deletions
diff --git a/views/controls/resize_area.cc b/views/controls/resize_area.cc
new file mode 100644
index 0000000..21afb62
--- /dev/null
+++ b/views/controls/resize_area.cc
@@ -0,0 +1,87 @@
+// 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 "views/controls/resize_area.h"
+
+#include "app/resource_bundle.h"
+#include "base/logging.h"
+
+namespace views {
+
+const char ResizeArea::kViewClassName[] = "views/ResizeArea";
+
+#if defined(OS_WIN)
+static HCURSOR g_resize_cursor = NULL;
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// ResizeArea
+
+ResizeArea::ResizeArea(ResizeAreaDelegate* delegate)
+ : delegate_(delegate),
+ initial_position_(0) {
+}
+
+ResizeArea::~ResizeArea() {
+}
+
+std::string ResizeArea::GetClassName() const {
+ return kViewClassName;
+}
+
+gfx::NativeCursor ResizeArea::GetCursorForPoint(Event::EventType event_type,
+ const gfx::Point& p) {
+ if (!enabled_)
+ return NULL;
+#if defined(OS_WIN)
+ if (!g_resize_cursor)
+ g_resize_cursor = LoadCursor(NULL, IDC_SIZEWE);
+ return g_resize_cursor;
+#elif defined(OS_LINUX)
+ return gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
+#endif
+}
+
+bool ResizeArea::OnMousePressed(const views::MouseEvent& event) {
+ if (!event.IsOnlyLeftMouseButton())
+ return false;
+
+ // The resize area obviously will move once you start dragging so we need to
+ // convert coordinates to screen coordinates so that we don't lose our
+ // bearings.
+ gfx::Point point(event.x(), 0);
+ View::ConvertPointToScreen(this, &point);
+ initial_position_ = point.x();
+
+ return true;
+}
+
+bool ResizeArea::OnMouseDragged(const views::MouseEvent& event) {
+ if (!event.IsLeftMouseButton())
+ return false;
+
+ ReportResizeAmount(event.x(), false);
+ return true;
+}
+
+void ResizeArea::OnMouseReleased(const views::MouseEvent& event,
+ bool canceled) {
+ ReportResizeAmount(canceled ? initial_position_ : event.x(), true);
+}
+
+bool ResizeArea::GetAccessibleRole(AccessibilityTypes::Role* role) {
+ DCHECK(role);
+ *role = AccessibilityTypes::ROLE_SEPARATOR;
+ return true;
+}
+
+void ResizeArea::ReportResizeAmount(int resize_amount, bool last_update) {
+ gfx::Point point(resize_amount, 0);
+ View::ConvertPointToScreen(this, &point);
+ resize_amount = point.x() - initial_position_;
+ delegate_->OnResize(base::i18n::IsRTL() ? -resize_amount : resize_amount,
+ last_update);
+}
+
+} // namespace views
diff --git a/views/controls/resize_gripper.h b/views/controls/resize_area.h
index c844ce8..cea7d0f 100644
--- a/views/controls/resize_gripper.h
+++ b/views/controls/resize_area.h
@@ -2,29 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef VIEWS_CONTROLS_RESIZE_GRIPPER_H_
-#define VIEWS_CONTROLS_RESIZE_GRIPPER_H_
+#ifndef VIEWS_CONTROLS_RESIZE_AREA_H_
+#define VIEWS_CONTROLS_RESIZE_AREA_H_
#pragma once
#include <string>
-#include "views/controls/image_view.h"
+#include "views/view.h"
namespace views {
////////////////////////////////////////////////////////////////////////////////
//
-// A simple resize gripper (two vertical bars).
+// An invisible area that acts like a horizontal resizer.
//
////////////////////////////////////////////////////////////////////////////////
-class ResizeGripper : public ImageView {
+class ResizeArea : public View {
public:
//////////////////////////////////////////////////////////////////////////////
//
// The interface needed for getting notified about the resize event.
//
//////////////////////////////////////////////////////////////////////////////
- class ResizeGripperDelegate {
+ class ResizeAreaDelegate {
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
@@ -37,15 +37,13 @@ class ResizeGripper : public ImageView {
static const char kViewClassName[];
- explicit ResizeGripper(ResizeGripperDelegate* delegate);
- virtual ~ResizeGripper();
+ explicit ResizeArea(ResizeAreaDelegate* delegate);
+ virtual ~ResizeArea();
// Overridden from views::View:
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);
@@ -56,22 +54,15 @@ class ResizeGripper : public ImageView {
// 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_;
+ ResizeAreaDelegate* 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);
+ DISALLOW_COPY_AND_ASSIGN(ResizeArea);
};
} // namespace views
-#endif // VIEWS_CONTROLS_RESIZE_GRIPPER_H_
+#endif // VIEWS_CONTROLS_RESIZE_AREA_H_
diff --git a/views/controls/resize_gripper.cc b/views/controls/resize_gripper.cc
deleted file mode 100644
index 2de05c2..0000000
--- a/views/controls/resize_gripper.cc
+++ /dev/null
@@ -1,123 +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 "views/controls/resize_gripper.h"
-
-#include "app/resource_bundle.h"
-#include "base/logging.h"
-#include "grit/app_resources.h"
-
-namespace views {
-
-const char ResizeGripper::kViewClassName[] = "views/ResizeGripper";
-
-#if defined(OS_WIN)
-static HCURSOR g_resize_cursor = NULL;
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// ResizeGripper
-
-ResizeGripper::ResizeGripper(ResizeGripperDelegate* delegate)
- : delegate_(delegate),
- initial_position_(0),
- gripper_visible_(false) {
- ResourceBundle &rb = ResourceBundle::GetSharedInstance();
- SkBitmap* gripper_image = rb.GetBitmapNamed(IDR_RESIZE_GRIPPER);
- // 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() {
-}
-
-std::string ResizeGripper::GetClassName() const {
- return kViewClassName;
-}
-
-gfx::NativeCursor ResizeGripper::GetCursorForPoint(Event::EventType event_type,
- const gfx::Point& p) {
- if (!enabled_)
- return NULL;
-#if defined(OS_WIN)
- if (!g_resize_cursor)
- g_resize_cursor = LoadCursor(NULL, IDC_SIZEWE);
- return g_resize_cursor;
-#elif defined(OS_LINUX)
- return gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
-#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;
-
- // The resize gripper obviously will move once you start dragging so we need
- // to convert coordinates to screen coordinates so that we don't loose our
- // bearings.
- gfx::Point point(event.x(), 0);
- View::ConvertPointToScreen(this, &point);
- initial_position_ = point.x();
-
- return true;
-}
-
-bool ResizeGripper::OnMouseDragged(const views::MouseEvent& event) {
- if (!event.IsLeftMouseButton())
- return false;
-
- ReportResizeAmount(event.x(), false);
- return true;
-}
-
-void ResizeGripper::OnMouseReleased(const views::MouseEvent& event,
- bool canceled) {
- if (canceled)
- ReportResizeAmount(initial_position_, true);
- else
- ReportResizeAmount(event.x(), true);
- SetGripperVisible(HitTest(event.location()));
-}
-
-bool ResizeGripper::GetAccessibleRole(AccessibilityTypes::Role* role) {
- DCHECK(role);
- *role = AccessibilityTypes::ROLE_SEPARATOR;
- return true;
-}
-
-void ResizeGripper::ReportResizeAmount(int resize_amount, bool last_update) {
- gfx::Point point(resize_amount, 0);
- View::ConvertPointToScreen(this, &point);
- resize_amount = point.x() - initial_position_;
-
- if (base::i18n::IsRTL())
- resize_amount = -1 * resize_amount;
- 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/views.gyp b/views/views.gyp
index d332604..1946a18 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -163,8 +163,8 @@
'controls/native/native_view_host_wrapper.h',
'controls/progress_bar.h',
'controls/progress_bar.cc',
- 'controls/resize_gripper.cc',
- 'controls/resize_gripper.h',
+ 'controls/resize_area.cc',
+ 'controls/resize_area.h',
'controls/scroll_view.cc',
'controls/scroll_view.h',
'controls/scrollbar/bitmap_scroll_bar.cc',