Commit 3d7caa70 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[VK] Make DragDescriptor a struct.

Currently, DragDescriptor is a simple class with a bunch of getters.
The C++ style guide suggests that DragDescriptor is better off as a
struct.

Change-Id: I0b982aea715627226bb2cd3ff924cde0d3c61f7c
Reviewed-on: https://chromium-review.googlesource.com/1056942Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558893}
parent 33ceacf0
......@@ -20,7 +20,6 @@ jumbo_component("keyboard") {
"container_fullscreen_behavior.h",
"display_util.cc",
"display_util.h",
"drag_descriptor.cc",
"drag_descriptor.h",
"keyboard_controller.cc",
"keyboard_controller.h",
......
......@@ -215,8 +215,8 @@ bool ContainerFloatingBehavior::HandlePointerEvent(
// If there is no active drag descriptor, start a new one.
bool drag_started_by_touch = (type == ui::ET_TOUCH_PRESSED);
drag_descriptor_.reset(
new DragDescriptor(keyboard_bounds.origin(), kb_offset,
drag_started_by_touch, pointer_id));
new DragDescriptor{keyboard_bounds.origin(), kb_offset,
drag_started_by_touch, pointer_id});
}
break;
......@@ -224,26 +224,26 @@ bool ContainerFloatingBehavior::HandlePointerEvent(
case ui::ET_TOUCH_MOVED:
if (!drag_descriptor_) {
// do nothing
} else if (drag_descriptor_->is_touch_drag() !=
} else if (drag_descriptor_->is_touch_drag !=
(type == ui::ET_TOUCH_MOVED)) {
// If the event isn't of the same type that started the drag, end the
// drag to prevent confusion.
drag_descriptor_ = nullptr;
} else if (drag_descriptor_->pointer_id() != pointer_id) {
} else if (drag_descriptor_->pointer_id != pointer_id) {
// do nothing.
} else {
// Drag continues.
// If there is an active drag, use it to determine the new location
// of the keyboard.
const gfx::Point original_click_location =
drag_descriptor_->original_keyboard_location() +
drag_descriptor_->original_click_offset();
drag_descriptor_->original_keyboard_location +
drag_descriptor_->original_click_offset;
const gfx::Point current_drag_location =
keyboard_bounds.origin() + kb_offset;
const gfx::Vector2d cumulative_drag_offset =
current_drag_location - original_click_location;
const gfx::Point new_keyboard_location =
drag_descriptor_->original_keyboard_location() +
drag_descriptor_->original_keyboard_location +
cumulative_drag_offset;
gfx::Rect new_bounds_in_local =
gfx::Rect(new_keyboard_location, keyboard_bounds.size());
......
......@@ -82,7 +82,7 @@ class KEYBOARD_EXPORT ContainerFloatingBehavior : public ContainerBehavior {
// Current state of a cursor drag to move the keyboard, if one exists.
// Otherwise nullptr.
std::unique_ptr<DragDescriptor> drag_descriptor_ = nullptr;
std::unique_ptr<const DragDescriptor> drag_descriptor_ = nullptr;
gfx::Rect draggable_area_ = gfx::Rect();
};
......
// Copyright 2017 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/keyboard/drag_descriptor.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h"
namespace keyboard {
DragDescriptor::DragDescriptor(const gfx::Point& keyboard_location,
const gfx::Vector2d& click_offset,
bool is_touch_drag,
ui::PointerId pointer_id)
: original_keyboard_location_(keyboard_location),
original_click_offset_(click_offset),
is_touch_drag_(is_touch_drag),
pointer_id_(pointer_id) {}
} // namespace keyboard
......@@ -16,31 +16,17 @@ namespace keyboard {
// the offset of the original click on the keyboard along with the original
// location of the keyboard and uses incoming mouse move events to determine
// where the keyboard should be placed using those offsets.
class DragDescriptor {
public:
DragDescriptor(const gfx::Point& keyboard_location,
const gfx::Vector2d& click_offset,
bool is_touch_drag,
ui::PointerId pointer_id);
gfx::Point original_keyboard_location() const {
return original_keyboard_location_;
}
gfx::Vector2d original_click_offset() const { return original_click_offset_; }
bool is_touch_drag() { return is_touch_drag_; }
ui::PointerId pointer_id() { return pointer_id_; }
private:
const gfx::Point original_keyboard_location_;
const gfx::Vector2d original_click_offset_;
struct DragDescriptor {
gfx::Point original_keyboard_location;
gfx::Vector2d original_click_offset;
// Distinguish whether the current drag is from a touch event or mouse event,
// so drag/move events can be filtered accordingly
const bool is_touch_drag_;
bool is_touch_drag;
// The pointer ID provided by the touch event to disambiguate multiple
// touch points. If this is a mouse event, then this value is -1.
const ui::PointerId pointer_id_;
ui::PointerId pointer_id;
};
} // namespace keyboard
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment