Skip to content

Commit

Permalink
Refactor touch selection quick menu
Browse files Browse the repository at this point in the history
To use the touch selection quick menu in the upcoming unified touch
selection, a new interface is added to ui/touch_selection with an
implementation for Views. The implementation mostly copied code from the
old implementation.

COLLABORATOR=mfomitchev
BUG=399721

Review URL: https://codereview.chromium.org/1019353003

Cr-Commit-Position: refs/heads/master@{#331924}
  • Loading branch information
mohsen authored and Commit bot committed May 29, 2015
1 parent 7a6acf6 commit 1d0063d
Show file tree
Hide file tree
Showing 20 changed files with 624 additions and 411 deletions.
7 changes: 7 additions & 0 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,13 @@
'../ui/views/views.gyp:views',
'../ui/views/views.gyp:views_test_support',
],
'conditions': [
['use_aura==1', {
'dependencies': [
'../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection',
],
}],
],
}],
['use_aura==0 or chromeos==1', {
'sources!': [
Expand Down
3 changes: 3 additions & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ if (!is_android) {
"../../ui/views/widget/desktop_aura/x11_topmost_window_finder_interactive_uitest.cc",
]
}
if (use_aura) {
deps += [ "//ui/touch_selection" ]
}
}

if (is_linux && !is_chromeos) {
Expand Down
15 changes: 5 additions & 10 deletions ui/touch_selection/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ component("touch_selection") {
"selection_event_type.h",
"touch_handle.cc",
"touch_handle.h",
"touch_handle_drawable_aura.cc",
"touch_handle_drawable_aura.h",
"touch_handle_orientation.h",
"touch_selection_controller.cc",
"touch_selection_controller.h",
Expand All @@ -27,30 +25,27 @@ component("touch_selection") {
defines = [ "UI_TOUCH_SELECTION_IMPLEMENTATION" ]

deps = [
"//skia:skia",
"//base:base",
"//ui/aura:aura",
"//ui/aura_extra:aura_extra",
"//ui/base:base",
"//ui/compositor:compositor",
"//ui/events:events",
"//ui/events:gesture_detection",
"//ui/gfx:gfx",
"//ui/gfx/geometry:geometry",
]

if (!use_aura) {
deps -= [
if (use_aura) {
deps += [
"//skia:skia",
"//ui/aura:aura",
"//ui/aura_extra:aura_extra",
"//ui/compositor:compositor",
"//ui/gfx:gfx",
]

sources -= [
sources += [
"touch_handle_drawable_aura.cc",
"touch_handle_drawable_aura.h",
"touch_selection_menu_runner.cc",
"touch_selection_menu_runner.h",
]
}
}
Expand Down
31 changes: 31 additions & 0 deletions ui/touch_selection/touch_selection_menu_runner.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2015 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/touch_selection/touch_selection_menu_runner.h"

namespace ui {
namespace {

TouchSelectionMenuRunner* g_touch_selection_menu_runner = nullptr;

} // namespace

TouchSelectionMenuRunner::~TouchSelectionMenuRunner() {
g_touch_selection_menu_runner = nullptr;
}

TouchSelectionMenuRunner* TouchSelectionMenuRunner::GetInstance() {
return g_touch_selection_menu_runner;
}

TouchSelectionMenuRunner::TouchSelectionMenuRunner() {
// TODO(mohsen): Ideally we should DCHECK that |g_touch_selection_menu_runner|
// is not set here, in order to make sure we don't create multiple menu
// runners accidentally. Currently, this is not possible because we can have
// multiple ViewsDelegate's at the same time which should not happen. See
// crbug.com/492991.
g_touch_selection_menu_runner = this;
}

} // namespace ui
65 changes: 65 additions & 0 deletions ui/touch_selection/touch_selection_menu_runner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2015 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_TOUCH_SELECTION_TOUCH_SELECTION_MENU_RUNNER_H_
#define UI_TOUCH_SELECTION_TOUCH_SELECTION_MENU_RUNNER_H_

#include "base/macros.h"
#include "ui/touch_selection/ui_touch_selection_export.h"

namespace aura {
class Window;
}

namespace gfx {
class Rect;
class Size;
}

namespace ui {

// Client interface for TouchSelectionMenuRunner.
class UI_TOUCH_SELECTION_EXPORT TouchSelectionMenuClient {
public:
virtual ~TouchSelectionMenuClient() {}

virtual bool IsCommandIdEnabled(int command_id) const = 0;
virtual void ExecuteCommand(int command_id, int event_flags) = 0;

// Called when the quick menu needs to run a context menu. Depending on the
// implementation, this may run the context menu synchronously, or request the
// menu to show up in which case the menu will run asynchronously at a later
// time.
virtual void RunContextMenu() = 0;
};

// An interface for the singleton object responsible for running touch selection
// quick menu.
class UI_TOUCH_SELECTION_EXPORT TouchSelectionMenuRunner {
public:
virtual ~TouchSelectionMenuRunner();

static TouchSelectionMenuRunner* GetInstance();

// Creates and displays the quick menu, if there is any command available.
// |anchor_rect| is in screen coordinates.
virtual void OpenMenu(TouchSelectionMenuClient* client,
const gfx::Rect& anchor_rect,
const gfx::Size& handle_image_size,
aura::Window* context) = 0;

virtual void CloseMenu() = 0;

virtual bool IsRunning() const = 0;

protected:
TouchSelectionMenuRunner();

private:
DISALLOW_COPY_AND_ASSIGN(TouchSelectionMenuRunner);
};

} // namespace ui

#endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_MENU_RUNNER_H_
4 changes: 4 additions & 0 deletions ui/touch_selection/ui_touch_selection.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
'touch_handle_orientation.h',
'touch_selection_controller.cc',
'touch_selection_controller.h',
'touch_selection_menu_runner.cc',
'touch_selection_menu_runner.h',
'ui_touch_selection_export.h',
],
'include_dirs': [
Expand All @@ -51,6 +53,8 @@
'sources!': [
'touch_handle_drawable_aura.cc',
'touch_handle_drawable_aura.h',
'touch_selection_menu_runner.cc',
'touch_selection_menu_runner.h',
],
}],
],
Expand Down
2 changes: 2 additions & 0 deletions ui/views/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ component("views") {
sources += gypi_values.views_aura_sources
deps += [
"//ui/aura",
"//ui/touch_selection",
"//ui/wm",
]
if (!is_chromeos) {
Expand Down Expand Up @@ -235,6 +236,7 @@ test("views_unittests") {
deps += [
"//ui/aura",
"//ui/aura:test_support",
"//ui/touch_selection",
"//ui/wm",
]
if (!is_chromeos) {
Expand Down
1 change: 1 addition & 0 deletions ui/views/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include_rules = [
"+ui/ozone/public",
"+ui/resources/grit/ui_resources.h",
"+ui/strings/grit/ui_strings.h",
"+ui/touch_selection",
"+ui/wm/core",
"+ui/wm/public",

Expand Down
157 changes: 0 additions & 157 deletions ui/views/touchui/touch_editing_menu.cc

This file was deleted.

Loading

0 comments on commit 1d0063d

Please sign in to comment.