Commit b78a6a6c authored by dbeam's avatar dbeam Committed by Commit bot

Revert of ash: Refactor touch hud drawing to ash/touch_hud. (patchset #11...

Revert of ash: Refactor touch hud drawing to ash/touch_hud. (patchset #11 id:200001 of https://codereview.chromium.org/2118223004/ )

Reason for revert:
Invalid GYP, broken Win x64 builder:
https://build.chromium.org/p/chromium/builders/Win%20x64/builds/2391

Original issue's description:
> ash: Refactor touch hud drawing to ash/touch_hud.
>
> This is part of the touch hud app for mustash (https://codereview.chromium.org/2092343002/).
>
> BUG=588311
> TEST=ash_unittests
>
> Committed: https://crrev.com/98caac0fdcd637a95eb27e72c9a4c0a487e72d25
> Cr-Commit-Position: refs/heads/master@{#405296}

TBR=sadrul@chromium.org,sky@chromium.org,jamescook@chromium.org,riajiang@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=588311

Review-Url: https://codereview.chromium.org/2145223002
Cr-Commit-Position: refs/heads/master@{#405306}
parent ab29f4c4
...@@ -26,7 +26,6 @@ component("ash") { ...@@ -26,7 +26,6 @@ component("ash") {
"//ash/strings", "//ash/strings",
] ]
deps = [ deps = [
"//ash/touch_hud",
"//base", "//base",
"//base:i18n", "//base:i18n",
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
...@@ -350,7 +349,6 @@ test("ash_unittests") { ...@@ -350,7 +349,6 @@ test("ash_unittests") {
":test_support_with_content", ":test_support_with_content",
"//ash/resources", "//ash/resources",
"//ash/strings", "//ash/strings",
"//ash/touch_hud",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/signin/core/account_id", "//components/signin/core/account_id",
......
...@@ -1071,7 +1071,6 @@ ...@@ -1071,7 +1071,6 @@
'../url/url.gyp:url_lib', '../url/url.gyp:url_lib',
'ash_resources.gyp:ash_resources', 'ash_resources.gyp:ash_resources',
'ash_strings.gyp:ash_strings', 'ash_strings.gyp:ash_strings',
'ash_touch_hud.gyp:ash_touch_hud',
], ],
'defines': [ 'defines': [
'ASH_IMPLEMENTATION', 'ASH_IMPLEMENTATION',
...@@ -1279,7 +1278,6 @@ ...@@ -1279,7 +1278,6 @@
'ash_strings.gyp:ash_strings', 'ash_strings.gyp:ash_strings',
'ash_strings.gyp:ash_test_strings', 'ash_strings.gyp:ash_test_strings',
'ash_test_support', 'ash_test_support',
'ash_touch_hud.gyp:ash_touch_hud',
'ash_with_content', 'ash_with_content',
], ],
'sources': [ 'sources': [
......
# Copyright 2016 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.
{
'targets': [
{
# GN version: //ash/touch_hud
'target_name': 'ash_touch_hud',
'type': '<(component)',
'dependencies': [
'../base/base.gyp:base',
'../skia/skia.gyp:skia',
'../ui/events/events.gyp:events',
'../ui/gfx/gfx.gyp:gfx',
'../ui/views/views.gyp:views',
],
'defines': [
'ASH_TOUCH_HUD_IMPLEMENTATION',
],
'sources': [
'touch_hud/ash_touch_hud_export.h',
'touch_hud/touch_hud_renderer.cc',
'touch_hud/touch_hud_renderer.h',
],
},
}
...@@ -6,25 +6,160 @@ ...@@ -6,25 +6,160 @@
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/touch_hud/touch_hud_renderer.h" #include "third_party/skia/include/effects/SkGradientShader.h"
#include "base/memory/ptr_util.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace ash { namespace ash {
const int kPointRadius = 20;
const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC);
const SkColor kProjectionStrokeColor = SK_ColorGRAY;
const int kProjectionAlpha = 0xB0;
const int kFadeoutDurationInMs = 250;
const int kFadeoutFrameRate = 60;
// TouchPointView draws a single touch point. This object manages its own
// lifetime and deletes itself upon fade-out completion or whenever |Remove()|
// is explicitly called.
class TouchPointView : public views::View,
public gfx::AnimationDelegate,
public views::WidgetObserver {
public:
explicit TouchPointView(views::Widget* parent_widget)
: circle_center_(kPointRadius + 1, kPointRadius + 1),
gradient_center_(SkPoint::Make(kPointRadius + 1, kPointRadius + 1)) {
SetPaintToLayer(true);
layer()->SetFillsBoundsOpaquely(false);
SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2));
stroke_paint_.setStyle(SkPaint::kStroke_Style);
stroke_paint_.setColor(kProjectionStrokeColor);
gradient_colors_[0] = kProjectionFillColor;
gradient_colors_[1] = kProjectionStrokeColor;
gradient_pos_[0] = SkFloatToScalar(0.9f);
gradient_pos_[1] = SkFloatToScalar(1.0f);
parent_widget->GetContentsView()->AddChildView(this);
parent_widget->AddObserver(this);
}
void UpdateTouch(const ui::TouchEvent& touch) {
if (touch.type() == ui::ET_TOUCH_RELEASED ||
touch.type() == ui::ET_TOUCH_CANCELLED) {
fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs,
kFadeoutFrameRate, this));
fadeout_->Start();
} else {
SetX(parent()->GetMirroredXInView(touch.root_location().x()) -
kPointRadius - 1);
SetY(touch.root_location().y() - kPointRadius - 1);
}
}
void Remove() { delete this; }
private:
~TouchPointView() override {
GetWidget()->RemoveObserver(this);
parent()->RemoveChildView(this);
}
// Overridden from views::View.
void OnPaint(gfx::Canvas* canvas) override {
int alpha = kProjectionAlpha;
if (fadeout_)
alpha = static_cast<int>(fadeout_->CurrentValueBetween(alpha, 0));
fill_paint_.setAlpha(alpha);
stroke_paint_.setAlpha(alpha);
fill_paint_.setShader(SkGradientShader::MakeRadial(
gradient_center_, SkIntToScalar(kPointRadius), gradient_colors_,
gradient_pos_, arraysize(gradient_colors_),
SkShader::kMirror_TileMode));
canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius),
fill_paint_);
canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius),
stroke_paint_);
}
// Overridden from gfx::AnimationDelegate.
void AnimationEnded(const gfx::Animation* animation) override {
DCHECK_EQ(fadeout_.get(), animation);
delete this;
}
void AnimationProgressed(const gfx::Animation* animation) override {
DCHECK_EQ(fadeout_.get(), animation);
SchedulePaint();
}
void AnimationCanceled(const gfx::Animation* animation) override {
AnimationEnded(animation);
}
// Overridden from views::WidgetObserver.
void OnWidgetDestroying(views::Widget* widget) override {
if (fadeout_)
fadeout_->Stop();
else
Remove();
}
const gfx::Point circle_center_;
const SkPoint gradient_center_;
SkPaint fill_paint_;
SkPaint stroke_paint_;
SkColor gradient_colors_[2];
SkScalar gradient_pos_[2];
std::unique_ptr<gfx::Animation> fadeout_;
DISALLOW_COPY_AND_ASSIGN(TouchPointView);
};
TouchHudProjection::TouchHudProjection(aura::Window* initial_root) TouchHudProjection::TouchHudProjection(aura::Window* initial_root)
: TouchObserverHUD(initial_root), : TouchObserverHUD(initial_root) {}
touch_hud_renderer_(new TouchHudRenderer(widget())) {}
TouchHudProjection::~TouchHudProjection() {} TouchHudProjection::~TouchHudProjection() {}
void TouchHudProjection::Clear() { void TouchHudProjection::Clear() {
touch_hud_renderer_->Clear(); for (std::map<int, TouchPointView*>::iterator iter = points_.begin();
iter != points_.end(); iter++)
iter->second->Remove();
points_.clear();
} }
void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) { void TouchHudProjection::OnTouchEvent(ui::TouchEvent* event) {
touch_hud_renderer_->HandleTouchEvent(*event); if (event->type() == ui::ET_TOUCH_PRESSED) {
TouchPointView* point = new TouchPointView(widget());
point->UpdateTouch(*event);
std::pair<std::map<int, TouchPointView*>::iterator, bool> result =
points_.insert(std::make_pair(event->touch_id(), point));
// If a |TouchPointView| is already mapped to the touch id, remove it and
// replace it with the new one.
if (!result.second) {
result.first->second->Remove();
result.first->second = point;
}
} else {
std::map<int, TouchPointView*>::iterator iter =
points_.find(event->touch_id());
if (iter != points_.end()) {
iter->second->UpdateTouch(*event);
if (event->type() == ui::ET_TOUCH_RELEASED ||
event->type() == ui::ET_TOUCH_CANCELLED)
points_.erase(iter);
}
}
} }
void TouchHudProjection::SetHudForRootWindowController( void TouchHudProjection::SetHudForRootWindowController(
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
namespace ash { namespace ash {
class TouchHudRenderer; class TouchPointView;
// A heads-up display to show active touch points on the screen. As a derivative // A heads-up display to show active touch points on the screen. As a derivative
// of TouchObserverHUD, objects of this class manage their own lifetime. // of TouchObserverHUD, objects of this class manage their own lifetime.
...@@ -33,8 +33,7 @@ class TouchHudProjection : public TouchObserverHUD { ...@@ -33,8 +33,7 @@ class TouchHudProjection : public TouchObserverHUD {
void UnsetHudForRootWindowController( void UnsetHudForRootWindowController(
RootWindowController* controller) override; RootWindowController* controller) override;
// TouchHudRenderer draws out the touch points. std::map<int, TouchPointView*> points_;
std::unique_ptr<TouchHudRenderer> touch_hud_renderer_;
DISALLOW_COPY_AND_ASSIGN(TouchHudProjection); DISALLOW_COPY_AND_ASSIGN(TouchHudProjection);
}; };
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "ash/test/display_manager_test_api.h" #include "ash/test/display_manager_test_api.h"
#include "ash/touch/touch_hud_debug.h" #include "ash/touch/touch_hud_debug.h"
#include "ash/touch/touch_hud_projection.h" #include "ash/touch/touch_hud_projection.h"
#include "ash/touch_hud/touch_hud_renderer.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -284,7 +283,7 @@ class TouchHudProjectionTest : public TouchHudTestBase { ...@@ -284,7 +283,7 @@ class TouchHudProjectionTest : public TouchHudTestBase {
} }
int GetInternalTouchPointsCount() { int GetInternalTouchPointsCount() {
return GetInternalTouchHudProjection()->touch_hud_renderer_->points_.size(); return GetInternalTouchHudProjection()->points_.size();
} }
void SendTouchEventToInternalHud(ui::EventType type, void SendTouchEventToInternalHud(ui::EventType type,
......
# Copyright 2016 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.
import("//build/config/ui.gni")
component("touch_hud") {
sources = [
"ash_touch_hud_export.h",
"touch_hud_renderer.cc",
"touch_hud_renderer.h",
]
defines = [ "ASH_TOUCH_HUD_IMPLEMENTATION" ]
deps = [
"//base",
"//skia",
"//ui/events",
"//ui/gfx",
"//ui/views",
]
}
// Copyright 2016 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 ASH_TOUCH_HUD_ASH_TOUCH_HUD_EXPORT_H_
#define ASH_TOUCH_HUD_ASH_TOUCH_HUD_EXPORT_H_
#if defined(COMPONENT_BUILD)
#if defined(WIN32)
#if defined(ASH_TOUCH_HUD_IMPLEMENTATION)
#define ASH_TOUCH_HUD_EXPORT __declspec(dllexport)
#else
#define ASH_TOUCH_HUD_EXPORT __declspec(dllimport)
#endif // defined(ASH_TOUCH_HUD_IMPLEMENTATION)
#else // defined(WIN32)
#if defined(ASH_TOUCH_HUD_IMPLEMENTATION)
#define ASH_TOUCH_HUD_EXPORT __attribute__((visibility("default")))
#else
#define ASH_TOUCH_HUD_EXPORT
#endif
#endif
#else // defined(COMPONENT_BUILD)
#define ASH_TOUCH_HUD_EXPORT
#endif
#endif // ASH_TOUCH_HUD_ASH_TOUCH_HUD_EXPORT_H_
// Copyright 2013 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 "ash/touch_hud/touch_hud_renderer.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/events/event.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
namespace ash {
const int kPointRadius = 20;
const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC);
const SkColor kProjectionStrokeColor = SK_ColorGRAY;
const int kProjectionAlpha = 0xB0;
const int kFadeoutDurationInMs = 250;
const int kFadeoutFrameRate = 60;
// TouchPointView draws a single touch point. This object manages its own
// lifetime and deletes itself upon fade-out completion or whenever |Destroy()|
// is explicitly called.
class TouchPointView : public views::View,
public gfx::AnimationDelegate,
public views::WidgetObserver {
public:
explicit TouchPointView(views::Widget* parent_widget)
: circle_center_(kPointRadius + 1, kPointRadius + 1),
gradient_center_(SkPoint::Make(kPointRadius + 1, kPointRadius + 1)) {
SetPaintToLayer(true);
layer()->SetFillsBoundsOpaquely(false);
SetSize(gfx::Size(2 * kPointRadius + 2, 2 * kPointRadius + 2));
stroke_paint_.setStyle(SkPaint::kStroke_Style);
stroke_paint_.setColor(kProjectionStrokeColor);
gradient_colors_[0] = kProjectionFillColor;
gradient_colors_[1] = kProjectionStrokeColor;
gradient_pos_[0] = SkFloatToScalar(0.9f);
gradient_pos_[1] = SkFloatToScalar(1.0f);
parent_widget->GetContentsView()->AddChildView(this);
parent_widget->AddObserver(this);
}
void UpdateTouch(const ui::LocatedEvent& touch) {
if (touch.type() == ui::ET_TOUCH_RELEASED ||
touch.type() == ui::ET_TOUCH_CANCELLED ||
touch.type() == ui::ET_POINTER_UP ||
touch.type() == ui::ET_POINTER_CANCELLED) {
fadeout_.reset(new gfx::LinearAnimation(kFadeoutDurationInMs,
kFadeoutFrameRate, this));
fadeout_->Start();
} else {
SetX(parent()->GetMirroredXInView(touch.root_location().x()) -
kPointRadius - 1);
SetY(touch.root_location().y() - kPointRadius - 1);
}
}
void Destroy() { delete this; }
private:
~TouchPointView() override {
GetWidget()->RemoveObserver(this);
parent()->RemoveChildView(this);
}
// Overridden from views::View.
void OnPaint(gfx::Canvas* canvas) override {
int alpha = kProjectionAlpha;
if (fadeout_)
alpha = static_cast<int>(fadeout_->CurrentValueBetween(alpha, 0));
fill_paint_.setAlpha(alpha);
stroke_paint_.setAlpha(alpha);
fill_paint_.setShader(SkGradientShader::MakeRadial(
gradient_center_, SkIntToScalar(kPointRadius), gradient_colors_,
gradient_pos_, arraysize(gradient_colors_),
SkShader::kMirror_TileMode));
canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius),
fill_paint_);
canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius),
stroke_paint_);
}
// Overridden from gfx::AnimationDelegate.
void AnimationEnded(const gfx::Animation* animation) override {
DCHECK_EQ(fadeout_.get(), animation);
delete this;
}
void AnimationProgressed(const gfx::Animation* animation) override {
DCHECK_EQ(fadeout_.get(), animation);
SchedulePaint();
}
void AnimationCanceled(const gfx::Animation* animation) override {
AnimationEnded(animation);
}
// Overridden from views::WidgetObserver.
void OnWidgetDestroying(views::Widget* widget) override {
if (fadeout_)
fadeout_->Stop();
else
Destroy();
}
const gfx::Point circle_center_;
const SkPoint gradient_center_;
SkPaint fill_paint_;
SkPaint stroke_paint_;
SkColor gradient_colors_[2];
SkScalar gradient_pos_[2];
std::unique_ptr<gfx::Animation> fadeout_;
DISALLOW_COPY_AND_ASSIGN(TouchPointView);
};
TouchHudRenderer::TouchHudRenderer(views::Widget* parent_widget)
: parent_widget_(parent_widget) {}
TouchHudRenderer::~TouchHudRenderer() {}
void TouchHudRenderer::Clear() {
for (std::map<int, TouchPointView*>::iterator iter = points_.begin();
iter != points_.end(); iter++)
iter->second->Destroy();
points_.clear();
}
void TouchHudRenderer::HandleTouchEvent(const ui::LocatedEvent& event) {
int id = 0;
if (event.IsTouchEvent()) {
id = event.AsTouchEvent()->touch_id();
} else {
DCHECK(event.IsPointerEvent());
DCHECK(event.AsPointerEvent()->pointer_details().pointer_type ==
ui::EventPointerType::POINTER_TYPE_TOUCH);
id = event.AsPointerEvent()->pointer_id();
}
if (event.type() == ui::ET_TOUCH_PRESSED ||
event.type() == ui::ET_POINTER_DOWN) {
TouchPointView* point = new TouchPointView(parent_widget_);
point->UpdateTouch(event);
std::pair<std::map<int, TouchPointView*>::iterator, bool> result =
points_.insert(std::make_pair(id, point));
// If a |TouchPointView| is already mapped to the touch id, destroy it and
// replace it with the new one.
if (!result.second) {
result.first->second->Destroy();
result.first->second = point;
}
} else {
std::map<int, TouchPointView*>::iterator iter = points_.find(id);
if (iter != points_.end()) {
iter->second->UpdateTouch(event);
if (event.type() == ui::ET_TOUCH_RELEASED ||
event.type() == ui::ET_TOUCH_CANCELLED ||
event.type() == ui::ET_POINTER_UP ||
event.type() == ui::ET_POINTER_CANCELLED)
points_.erase(iter);
}
}
}
} // namespace ash
// Copyright 2016 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 ASH_TOUCH_HUD_TOUCH_HUD_RENDERER_H_
#define ASH_TOUCH_HUD_TOUCH_HUD_RENDERER_H_
#include <map>
#include "ash/touch_hud/ash_touch_hud_export.h"
#include "base/macros.h"
namespace ui {
class LocatedEvent;
}
namespace views {
class Widget;
}
namespace ash {
class TouchHudProjectionTest;
class TouchPointView;
// Handles touch events to draw out touch points accordingly.
class ASH_TOUCH_HUD_EXPORT TouchHudRenderer {
public:
explicit TouchHudRenderer(views::Widget* parent_widget);
~TouchHudRenderer();
// Called to clear touch points and traces from the screen.
void Clear();
// Receives a touch event and draws its touch point.
void HandleTouchEvent(const ui::LocatedEvent& event);
private:
friend class TouchHudProjectionTest;
// The parent widget that all touch points would be drawn in.
views::Widget* parent_widget_;
// A map of touch ids to TouchPointView.
std::map<int, TouchPointView*> points_;
DISALLOW_COPY_AND_ASSIGN(TouchHudRenderer);
};
} // namespace ash
#endif // ASH_TOUCH_HUD_TOUCH_HUD_RENDERER_H_
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