Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: views/controls/resize_gripper.cc

Issue 3052011: Make the resize gripper invisible.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/resize_gripper.h ('k') | views/views.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "views/controls/resize_gripper.h"
6
7 #include "app/resource_bundle.h"
8 #include "base/logging.h"
9 #include "grit/app_resources.h"
10
11 namespace views {
12
13 const char ResizeGripper::kViewClassName[] = "views/ResizeGripper";
14
15 #if defined(OS_WIN)
16 static HCURSOR g_resize_cursor = NULL;
17 #endif
18
19 ////////////////////////////////////////////////////////////////////////////////
20 // ResizeGripper
21
22 ResizeGripper::ResizeGripper(ResizeGripperDelegate* delegate)
23 : delegate_(delegate),
24 initial_position_(0),
25 gripper_visible_(false) {
26 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
27 SkBitmap* gripper_image = rb.GetBitmapNamed(IDR_RESIZE_GRIPPER);
28 // Explicitly set the image size so that the preferred size is fixed to that
29 // of the image. If we didn't do this the preferred size would change
30 // depending upon whether the gripper was visible.
31 SetImageSize(gfx::Size(gripper_image->width(), gripper_image->height()));
32 }
33
34 ResizeGripper::~ResizeGripper() {
35 }
36
37 std::string ResizeGripper::GetClassName() const {
38 return kViewClassName;
39 }
40
41 gfx::NativeCursor ResizeGripper::GetCursorForPoint(Event::EventType event_type,
42 const gfx::Point& p) {
43 if (!enabled_)
44 return NULL;
45 #if defined(OS_WIN)
46 if (!g_resize_cursor)
47 g_resize_cursor = LoadCursor(NULL, IDC_SIZEWE);
48 return g_resize_cursor;
49 #elif defined(OS_LINUX)
50 return gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
51 #endif
52 }
53
54 void ResizeGripper::OnMouseEntered(const views::MouseEvent& event) {
55 SetGripperVisible(true);
56 }
57
58 void ResizeGripper::OnMouseExited(const views::MouseEvent& event) {
59 SetGripperVisible(false);
60 }
61
62 bool ResizeGripper::OnMousePressed(const views::MouseEvent& event) {
63 if (!event.IsOnlyLeftMouseButton())
64 return false;
65
66 // The resize gripper obviously will move once you start dragging so we need
67 // to convert coordinates to screen coordinates so that we don't loose our
68 // bearings.
69 gfx::Point point(event.x(), 0);
70 View::ConvertPointToScreen(this, &point);
71 initial_position_ = point.x();
72
73 return true;
74 }
75
76 bool ResizeGripper::OnMouseDragged(const views::MouseEvent& event) {
77 if (!event.IsLeftMouseButton())
78 return false;
79
80 ReportResizeAmount(event.x(), false);
81 return true;
82 }
83
84 void ResizeGripper::OnMouseReleased(const views::MouseEvent& event,
85 bool canceled) {
86 if (canceled)
87 ReportResizeAmount(initial_position_, true);
88 else
89 ReportResizeAmount(event.x(), true);
90 SetGripperVisible(HitTest(event.location()));
91 }
92
93 bool ResizeGripper::GetAccessibleRole(AccessibilityTypes::Role* role) {
94 DCHECK(role);
95 *role = AccessibilityTypes::ROLE_SEPARATOR;
96 return true;
97 }
98
99 void ResizeGripper::ReportResizeAmount(int resize_amount, bool last_update) {
100 gfx::Point point(resize_amount, 0);
101 View::ConvertPointToScreen(this, &point);
102 resize_amount = point.x() - initial_position_;
103
104 if (base::i18n::IsRTL())
105 resize_amount = -1 * resize_amount;
106 delegate_->OnResize(resize_amount, last_update);
107 }
108
109 void ResizeGripper::SetGripperVisible(bool visible) {
110 if (visible == gripper_visible_)
111 return;
112
113 gripper_visible_ = visible;
114 if (gripper_visible_) {
115 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
116 SkBitmap* gripper_image = rb.GetBitmapNamed(IDR_RESIZE_GRIPPER);
117 SetImage(gripper_image);
118 } else {
119 SetImage(NULL);
120 }
121 }
122
123 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/resize_gripper.h ('k') | views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698