diff options
author | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-25 23:01:43 +0000 |
---|---|---|
committer | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-25 23:01:43 +0000 |
commit | 01644b15da47748a28fb595a9ead316965891113 (patch) | |
tree | c3af6592f1efa77347d942a66f4a5239c9b855c7 | |
parent | 141e6490d98ac90b9a4898b6a52c08e7ec98b08a (diff) | |
download | chromium_src-01644b15da47748a28fb595a9ead316965891113.zip chromium_src-01644b15da47748a28fb595a9ead316965891113.tar.gz chromium_src-01644b15da47748a28fb595a9ead316965891113.tar.bz2 |
MacViews: Introduce native_cursor.h to provide cursor "literals"
The ui:: cursors constants like ui::kCursorIBeam are gfx::NativeCursors
on aura, but not other platforms.
This change introduces ui/views/native_cursor.h, which provides a set of
functions giving gfx::NativeCursor constants in a platform-independent
way.
BUG=366007
Review URL: https://codereview.chromium.org/248863002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266269 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ui/views/controls/link.cc | 3 | ||||
-rw-r--r-- | ui/views/controls/resize_area.cc | 4 | ||||
-rw-r--r-- | ui/views/controls/single_split_view.cc | 5 | ||||
-rw-r--r-- | ui/views/controls/table/table_header.cc | 3 | ||||
-rw-r--r-- | ui/views/controls/textfield/textfield.cc | 3 | ||||
-rw-r--r-- | ui/views/native_cursor.h | 21 | ||||
-rw-r--r-- | ui/views/native_cursor_aura.cc | 31 | ||||
-rw-r--r-- | ui/views/native_cursor_mac.mm | 39 | ||||
-rw-r--r-- | ui/views/views.gyp | 3 |
9 files changed, 106 insertions, 6 deletions
diff --git a/ui/views/controls/link.cc b/ui/views/controls/link.cc index 2ccaa7b..84ff1de 100644 --- a/ui/views/controls/link.cc +++ b/ui/views/controls/link.cc @@ -16,6 +16,7 @@ #include "ui/gfx/color_utils.h" #include "ui/gfx/font_list.h" #include "ui/views/controls/link_listener.h" +#include "ui/views/native_cursor.h" namespace views { @@ -47,7 +48,7 @@ const char* Link::GetClassName() const { gfx::NativeCursor Link::GetCursor(const ui::MouseEvent& event) { if (!enabled()) return gfx::kNullCursor; - return ui::kCursorHand; + return GetNativeHandCursor(); } bool Link::HitTestRect(const gfx::Rect& rect) const { diff --git a/ui/views/controls/resize_area.cc b/ui/views/controls/resize_area.cc index 6c2f20c..8a5159f 100644 --- a/ui/views/controls/resize_area.cc +++ b/ui/views/controls/resize_area.cc @@ -9,6 +9,7 @@ #include "ui/base/cursor/cursor.h" #include "ui/base/resource/resource_bundle.h" #include "ui/views/controls/resize_area_delegate.h" +#include "ui/views/native_cursor.h" namespace views { @@ -30,7 +31,8 @@ const char* ResizeArea::GetClassName() const { } gfx::NativeCursor ResizeArea::GetCursor(const ui::MouseEvent& event) { - return enabled() ? ui::kCursorEastWestResize : gfx::kNullCursor; + return enabled() ? GetNativeEastWestResizeCursor() + : gfx::kNullCursor; } bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) { diff --git a/ui/views/controls/single_split_view.cc b/ui/views/controls/single_split_view.cc index 29b49a34..5909ed1 100644 --- a/ui/views/controls/single_split_view.cc +++ b/ui/views/controls/single_split_view.cc @@ -10,6 +10,7 @@ #include "ui/gfx/canvas.h" #include "ui/views/background.h" #include "ui/views/controls/single_split_view_listener.h" +#include "ui/views/native_cursor.h" namespace views { @@ -88,8 +89,8 @@ gfx::Size SingleSplitView::GetPreferredSize() { gfx::NativeCursor SingleSplitView::GetCursor(const ui::MouseEvent& event) { if (!IsPointInDivider(event.location())) return gfx::kNullCursor; - return is_horizontal_ ? - ui::kCursorEastWestResize : ui::kCursorNorthSouthResize; + return is_horizontal_ ? GetNativeEastWestResizeCursor() + : GetNativeNorthSouthResizeCursor(); } int SingleSplitView::GetDividerSize() const { diff --git a/ui/views/controls/table/table_header.cc b/ui/views/controls/table/table_header.cc index 9550f35..db0d3a9 100644 --- a/ui/views/controls/table/table_header.cc +++ b/ui/views/controls/table/table_header.cc @@ -12,6 +12,7 @@ #include "ui/views/background.h" #include "ui/views/controls/table/table_utils.h" #include "ui/views/controls/table/table_view.h" +#include "ui/views/native_cursor.h" namespace views { @@ -164,7 +165,7 @@ gfx::Size TableHeader::GetPreferredSize() { gfx::NativeCursor TableHeader::GetCursor(const ui::MouseEvent& event) { return GetResizeColumn(GetMirroredXInView(event.x())) != -1 ? - ui::kCursorColumnResize : View::GetCursor(event); + GetNativeColumnResizeCursor() : View::GetCursor(event); } bool TableHeader::OnMousePressed(const ui::MouseEvent& event) { diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc index f2c16a4..9978264 100644 --- a/ui/views/controls/textfield/textfield.cc +++ b/ui/views/controls/textfield/textfield.cc @@ -32,6 +32,7 @@ #include "ui/views/drag_utils.h" #include "ui/views/ime/input_method.h" #include "ui/views/metrics.h" +#include "ui/views/native_cursor.h" #include "ui/views/painter.h" #include "ui/views/views_delegate.h" #include "ui/views/widget/widget.h" @@ -487,7 +488,7 @@ gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) { bool in_selection = GetRenderText()->IsPointInSelection(event.location()); bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); - return text_cursor ? ui::kCursorIBeam : ui::kCursorNull; + return text_cursor ? GetNativeIBeamCursor() : gfx::kNullCursor; } bool Textfield::OnMousePressed(const ui::MouseEvent& event) { diff --git a/ui/views/native_cursor.h b/ui/views/native_cursor.h new file mode 100644 index 0000000..81f6e21 --- /dev/null +++ b/ui/views/native_cursor.h @@ -0,0 +1,21 @@ +// Copyright 2014 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. + +#ifndef UI_VIEWS_NATIVE_CURSOR_H_ +#define UI_VIEWS_NATIVE_CURSOR_H_ + +#include "ui/gfx/native_widget_types.h" +#include "ui/views/views_export.h" + +namespace views { + +VIEWS_EXPORT gfx::NativeCursor GetNativeIBeamCursor(); +VIEWS_EXPORT gfx::NativeCursor GetNativeHandCursor(); +VIEWS_EXPORT gfx::NativeCursor GetNativeColumnResizeCursor(); +VIEWS_EXPORT gfx::NativeCursor GetNativeEastWestResizeCursor(); +VIEWS_EXPORT gfx::NativeCursor GetNativeNorthSouthResizeCursor(); + +} // namespace views + +#endif // UI_VIEWS_NATIVE_CURSOR_H_ diff --git a/ui/views/native_cursor_aura.cc b/ui/views/native_cursor_aura.cc new file mode 100644 index 0000000..cafe684 --- /dev/null +++ b/ui/views/native_cursor_aura.cc @@ -0,0 +1,31 @@ +// Copyright 2014 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 "ui/views/native_cursor.h" + +#include "ui/base/cursor/cursor.h" + +namespace views { + +gfx::NativeCursor GetNativeIBeamCursor() { + return ui::kCursorIBeam; +} + +gfx::NativeCursor GetNativeHandCursor() { + return ui::kCursorHand; +} + +gfx::NativeCursor GetNativeColumnResizeCursor() { + return ui::kCursorColumnResize; +} + +gfx::NativeCursor GetNativeEastWestResizeCursor() { + return ui::kCursorEastWestResize; +} + +gfx::NativeCursor GetNativeNorthSouthResizeCursor() { + return ui::kCursorNorthSouthResize; +} + +} // namespace views diff --git a/ui/views/native_cursor_mac.mm b/ui/views/native_cursor_mac.mm new file mode 100644 index 0000000..967484d --- /dev/null +++ b/ui/views/native_cursor_mac.mm @@ -0,0 +1,39 @@ +// Copyright 2014 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 "ui/views/native_cursor.h" + +#include <Cocoa/Cocoa.h> + +namespace views { + +gfx::NativeCursor GetNativeIBeamCursor() { + return [NSCursor IBeamCursor]; +} + +gfx::NativeCursor GetNativeArrowCursor() { + return [NSCursor arrowCursor]; +} + +gfx::NativeCursor GetNativeHandCursor() { + return [NSCursor pointingHandCursor]; +} + +gfx::NativeCursor GetNativeColumnResizeCursor() { + return [NSCursor resizeLeftRightCursor]; +} + +gfx::NativeCursor GetNativeEastWestResizeCursor() { + NOTIMPLEMENTED(); + // TODO(tapted): This is the wrong cursor. Fetch the right one from WebCursor + // or ResourceBundle or CoreCursor private API. + return [NSCursor resizeLeftRightCursor]; +} + +gfx::NativeCursor GetNativeNorthSouthResizeCursor() { + NOTIMPLEMENTED(); + return [NSCursor resizeUpDownCursor]; +} + +} // namespace views diff --git a/ui/views/views.gyp b/ui/views/views.gyp index 15e9247..a1b2f5a 100644 --- a/ui/views/views.gyp +++ b/ui/views/views.gyp @@ -275,6 +275,9 @@ 'mouse_watcher.h', 'mouse_watcher_view_host.cc', 'mouse_watcher_view_host.h', + 'native_cursor.h', + 'native_cursor_aura.cc', + 'native_cursor_mac.mm', 'native_theme_delegate.h', 'painter.cc', 'painter.h', |