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

Unified Diff: ui/ozone/platform/dri/dri_cursor.cc

Issue 556073003: [Ozone-DRI] Do proper bounds checks when moving the cursor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@restore-cursor
Patch Set: Cache window Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/ozone/platform/dri/dri_cursor.h ('k') | ui/ozone/platform/dri/dri_surface_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/platform/dri/dri_cursor.cc
diff --git a/ui/ozone/platform/dri/dri_cursor.cc b/ui/ozone/platform/dri/dri_cursor.cc
index a6fe5fe0f71f8f8091cf1f1788d30410430df571..c9c759af3df42e99906327aa8e30bbc4f3a9df77 100644
--- a/ui/ozone/platform/dri/dri_cursor.cc
+++ b/ui/ozone/platform/dri/dri_cursor.cc
@@ -9,15 +9,18 @@
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/ozone/platform/dri/dri_surface_factory.h"
+#include "ui/ozone/platform/dri/dri_window.h"
+#include "ui/ozone/platform/dri/dri_window_manager.h"
#include "ui/ozone/platform/dri/hardware_cursor_delegate.h"
namespace ui {
-DriCursor::DriCursor(HardwareCursorDelegate* hardware) : hardware_(hardware) {
- // TODO(dnicoara) Assume the first widget since at this point there are no
- // widgets initialized.
- cursor_window_ = DriSurfaceFactory::kDefaultWidgetHandle;
- cursor_location_ = gfx::PointF(2560 / 2, 1700 / 2); // TODO(spang): Argh!
+DriCursor::DriCursor(HardwareCursorDelegate* hardware,
+ DriWindowManager* window_manager)
+ : hardware_(hardware),
+ window_manager_(window_manager),
+ cursor_widget_(gfx::kNullAcceleratedWidget),
+ cursor_window_(NULL) {
}
DriCursor::~DriCursor() {
@@ -27,7 +30,7 @@ void DriCursor::SetCursor(gfx::AcceleratedWidget widget,
PlatformCursor platform_cursor) {
scoped_refptr<BitmapCursorOzone> cursor =
BitmapCursorFactoryOzone::GetBitmapCursor(platform_cursor);
- if (cursor_ == cursor || cursor_window_ != widget)
+ if (cursor_ == cursor || cursor_widget_ != widget)
return;
cursor_ = cursor;
@@ -35,8 +38,9 @@ void DriCursor::SetCursor(gfx::AcceleratedWidget widget,
}
void DriCursor::ShowCursor() {
+ DCHECK_NE(cursor_widget_, gfx::kNullAcceleratedWidget);
if (cursor_.get())
- hardware_->SetHardwareCursor(cursor_window_,
+ hardware_->SetHardwareCursor(cursor_widget_,
cursor_->bitmaps(),
bitmap_location(),
cursor_->frame_delay_ms());
@@ -45,32 +49,38 @@ void DriCursor::ShowCursor() {
}
void DriCursor::HideCursor() {
+ DCHECK_NE(cursor_widget_, gfx::kNullAcceleratedWidget);
hardware_->SetHardwareCursor(
- cursor_window_, std::vector<SkBitmap>(), gfx::Point(), 0);
+ cursor_widget_, std::vector<SkBitmap>(), gfx::Point(), 0);
}
void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget,
const gfx::PointF& location) {
- if (widget != cursor_window_)
- HideCursor();
+ DCHECK_NE(widget, gfx::kNullAcceleratedWidget);
+ if (widget != cursor_widget_) {
+ if (cursor_widget_ != gfx::kNullAcceleratedWidget)
spang 2014/09/12 19:28:39 Can you move this into HideCursor and lose the DCH
dnicoara 2014/09/12 20:24:17 I'd prefer to keep this in here since it is only n
+ HideCursor();
+
+ cursor_widget_ = widget;
spang 2014/09/12 19:28:39 There's no reason for these assignments to be done
dnicoara 2014/09/12 20:24:17 I felt like cursor_widget_ and cursor_window_ shou
+ cursor_window_ = window_manager_->GetWindow(widget);
spang 2014/09/12 19:28:39 How do you ensure this ptr doesn't become dangling
dnicoara 2014/09/12 20:24:17 Setting/moving the cursor on an invalid widget is
spang 2014/09/12 21:05:47 What if you delete the window under the cursor, wh
dnicoara 2014/09/12 21:24:52 Can't happen at the same time since all the change
+ }
- cursor_window_ = widget;
cursor_location_ = location;
- gfx::Size size = gfx::Size(2560, 1700); // TODO(spang): Fix.
+ const gfx::Size& size = cursor_window_->GetBounds().size();
spang 2014/09/12 19:28:39 gfx::Size size =
cursor_location_.SetToMax(gfx::PointF(0, 0));
cursor_location_.SetToMin(gfx::PointF(size.width(), size.height()));
if (cursor_.get())
- hardware_->MoveHardwareCursor(cursor_window_, bitmap_location());
+ hardware_->MoveHardwareCursor(cursor_widget_, bitmap_location());
}
void DriCursor::MoveCursor(const gfx::Vector2dF& delta) {
- MoveCursorTo(cursor_window_, cursor_location_ + delta);
+ MoveCursorTo(cursor_widget_, cursor_location_ + delta);
}
gfx::AcceleratedWidget DriCursor::GetCursorWindow() {
- return cursor_window_;
+ return cursor_widget_;
}
bool DriCursor::IsCursorVisible() {
« no previous file with comments | « ui/ozone/platform/dri/dri_cursor.h ('k') | ui/ozone/platform/dri/dri_surface_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698