Chromium Code Reviews| Index: ash/touch/touch_hud_debug.cc |
| diff --git a/ash/touch/touch_observer_hud.cc b/ash/touch/touch_hud_debug.cc |
| similarity index 56% |
| copy from ash/touch/touch_observer_hud.cc |
| copy to ash/touch/touch_hud_debug.cc |
| index a9ac307be1efe86d11fd39d9bdb40f8966f3665d..f98fd4dbee5a45209ae6c00b03d23ec63243fee3 100644 |
| --- a/ash/touch/touch_observer_hud.cc |
| +++ b/ash/touch/touch_hud_debug.cc |
| @@ -1,33 +1,25 @@ |
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 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/touch_observer_hud.h" |
| +#include "ash/touch/touch_hud_debug.h" |
| -#include "ash/display/display_controller.h" |
| #include "ash/display/display_manager.h" |
| #include "ash/root_window_controller.h" |
| -#include "ash/shell_window_ids.h" |
| +#include "ash/shell.h" |
| #include "ash/wm/property_util.h" |
| #include "base/json/json_string_value_serializer.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "third_party/skia/include/core/SkPath.h" |
| -#include "third_party/skia/include/core/SkXfermode.h" |
| -#include "third_party/skia/include/effects/SkGradientShader.h" |
| #include "ui/aura/root_window.h" |
| -#include "ui/aura/window.h" |
| #include "ui/base/animation/animation_delegate.h" |
| -#include "ui/base/animation/linear_animation.h" |
| #include "ui/base/events/event.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/display.h" |
| -#include "ui/gfx/rect.h" |
| -#include "ui/gfx/screen.h" |
| #include "ui/gfx/size.h" |
| #include "ui/gfx/transform.h" |
| -#include "ui/views/background.h" |
| #include "ui/views/controls/label.h" |
| #include "ui/views/layout/box_layout.h" |
| #include "ui/views/widget/widget.h" |
| @@ -58,13 +50,8 @@ const SkColor kColors[] = { |
| SkColorSetRGB(0xFF, 0xDE, 0xAD), |
| }; |
| const int kAlpha = 0x60; |
| -const SkColor kProjectionFillColor = SkColorSetRGB(0xF5, 0xF5, 0xDC); |
| -const SkColor kProjectionStrokeColor = SK_ColorGRAY; |
| -const int kProjectionAlpha = 0xB0; |
| const int kMaxPaths = arraysize(kColors); |
| const int kReducedScale = 10; |
| -const int kFadeoutDurationInMs = 250; |
| -const int kFadeoutFrameRate = 60; |
| const char* GetTouchEventLabel(ui::EventType type) { |
| switch (type) { |
| @@ -154,7 +141,7 @@ struct TouchPointLog { |
| }; |
| // A TouchTrace keeps track of all the touch events of a single touch point |
| -// (starting from a touch-press and ending at touch-release). |
| +// (starting from a touch-press and ending at a touch-release or touch-cancel). |
| class TouchTrace { |
| public: |
| typedef std::vector<TouchPointLog>::iterator iterator; |
| @@ -343,131 +330,20 @@ class TouchHudCanvas : public views::View { |
| DISALLOW_COPY_AND_ASSIGN(TouchHudCanvas); |
| }; |
| -// TouchPointView draws a single touch point in |PROJECTION| mode. 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 ui::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); |
| - 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 ui::LinearAnimation(kFadeoutDurationInMs, |
| - kFadeoutFrameRate, |
| - this)); |
| - fadeout_->Start(); |
| - } else { |
| - SetX(touch.root_location().x() - kPointRadius - 1); |
| - SetY(touch.root_location().y() - kPointRadius - 1); |
| - } |
| - } |
| - |
| - void Remove() { |
| - delete this; |
| - } |
| - |
| - private: |
| - virtual ~TouchPointView() { |
| - GetWidget()->RemoveObserver(this); |
| - parent()->RemoveChildView(this); |
| - } |
| - |
| - // Overridden from views::View. |
| - virtual 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); |
| - SkShader* shader = SkGradientShader::CreateRadial( |
| - gradient_center_, |
| - SkIntToScalar(kPointRadius), |
| - gradient_colors_, |
| - gradient_pos_, |
| - arraysize(gradient_colors_), |
| - SkShader::kMirror_TileMode, |
| - NULL); |
| - fill_paint_.setShader(shader); |
| - shader->unref(); |
| - canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius), |
| - fill_paint_); |
| - canvas->DrawCircle(circle_center_, SkIntToScalar(kPointRadius), |
| - stroke_paint_); |
| - } |
| - |
| - // Overridden from ui::AnimationDelegate. |
| - virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE { |
| - DCHECK_EQ(fadeout_.get(), animation); |
| - delete this; |
| - } |
| - |
| - virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE { |
| - DCHECK_EQ(fadeout_.get(), animation); |
| - SchedulePaint(); |
| - } |
| - |
| - virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE { |
| - AnimationEnded(animation); |
| - } |
| - |
| - // Overridden from views::WidgetObserver. |
| - virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { |
| - fadeout_->Stop(); |
| - } |
| - |
| - const gfx::Point circle_center_; |
| - const SkPoint gradient_center_; |
| - |
| - SkPaint fill_paint_; |
| - SkPaint stroke_paint_; |
| - SkColor gradient_colors_[2]; |
| - SkScalar gradient_pos_[2]; |
| - |
| - scoped_ptr<ui::Animation> fadeout_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(TouchPointView); |
| -}; |
| - |
| -TouchObserverHUD::TouchObserverHUD(aura::RootWindow* initial_root) |
| - : display_id_(initial_root->GetProperty(kDisplayIdKey)), |
| - root_window_(initial_root), |
| +TouchHudDebug::TouchHudDebug(aura::RootWindow* initial_root) |
| + : TouchObserverHUD(initial_root), |
| mode_(FULLSCREEN), |
| touch_log_(new TouchLog()) { |
|
sky
2013/06/26 21:07:44
Please member initialize all primitives/pointers (
mohsen
2013/06/27 00:44:31
Done.
(Isn't it enough that they're initialized in
sky
2013/06/28 16:09:00
Your argument equally applies to whether you shoul
|
| const gfx::Display& display = |
| - Shell::GetInstance()->display_manager()->GetDisplayForId(display_id_); |
| + Shell::GetInstance()->display_manager()->GetDisplayForId(display_id()); |
| - views::View* content = new views::View; |
| + views::View* content = widget()->GetContentsView(); |
| canvas_ = new TouchHudCanvas(*touch_log_); |
| content->AddChildView(canvas_); |
| const gfx::Size& display_size = display.size(); |
| canvas_->SetSize(display_size); |
| - content->SetSize(display_size); |
| label_container_ = new views::View; |
| label_container_->SetLayoutManager(new views::BoxLayout( |
| @@ -486,72 +362,34 @@ TouchObserverHUD::TouchObserverHUD(aura::RootWindow* initial_root) |
| label_container_->SetSize(label_container_->GetPreferredSize()); |
| label_container_->SetVisible(false); |
| content->AddChildView(label_container_); |
| - |
| - widget_ = new views::Widget(); |
| - views::Widget::InitParams |
| - params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| - params.transparent = true; |
| - params.can_activate = false; |
| - params.accept_events = false; |
| - params.bounds = gfx::Rect(display_size); |
| - params.parent = Shell::GetContainer( |
| - root_window_, |
| - internal::kShellWindowId_OverlayContainer); |
| - widget_->Init(params); |
| - widget_->SetContentsView(content); |
| - widget_->StackAtTop(); |
| - widget_->Show(); |
| - |
| - widget_->AddObserver(this); |
| - |
| - // Observe changes in display size and mode to update touch HUD. |
| - Shell::GetScreen()->AddObserver(this); |
| -#if defined(OS_CHROMEOS) |
| - Shell::GetInstance()->output_configurator()->AddObserver(this); |
| -#endif // defined(OS_CHROMEOS) |
| - |
| - Shell::GetInstance()->display_controller()->AddObserver(this); |
| - root_window_->AddPreTargetHandler(this); |
| } |
| -TouchObserverHUD::~TouchObserverHUD() { |
| - Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| - |
| -#if defined(OS_CHROMEOS) |
| - Shell::GetInstance()->output_configurator()->RemoveObserver(this); |
| -#endif // defined(OS_CHROMEOS) |
| - Shell::GetScreen()->RemoveObserver(this); |
| - |
| - widget_->RemoveObserver(this); |
| +TouchHudDebug::~TouchHudDebug() { |
| } |
| // static |
| -scoped_ptr<DictionaryValue> TouchObserverHUD::GetAllAsDictionary() { |
| +scoped_ptr<DictionaryValue> TouchHudDebug::GetAllAsDictionary() { |
| scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| Shell::RootWindowList roots = Shell::GetInstance()->GetAllRootWindows(); |
| for (Shell::RootWindowList::iterator iter = roots.begin(); |
| iter != roots.end(); ++iter) { |
| internal::RootWindowController* controller = GetRootWindowController(*iter); |
| - if (controller->touch_observer_hud()) { |
| - int64 display_id = (*iter)->GetProperty(kDisplayIdKey); |
| - scoped_ptr<ListValue> list = |
| - controller->touch_observer_hud()->GetLogAsList(); |
| + internal::TouchHudDebug* hud = controller->touch_hud_debug(); |
| + if (hud) { |
| + scoped_ptr<ListValue> list = hud->GetLogAsList(); |
| if (!list->empty()) |
| - value->Set(base::Int64ToString(display_id), list.release()); |
| + value->Set(base::Int64ToString(hud->display_id()), list.release()); |
| } |
| } |
| return value.Pass(); |
| } |
| -void TouchObserverHUD::ChangeToNextMode() { |
| +void TouchHudDebug::ChangeToNextMode() { |
| switch (mode_) { |
| case FULLSCREEN: |
| SetMode(REDUCED_SCALE); |
| break; |
| case REDUCED_SCALE: |
| - SetMode(PROJECTION); |
| - break; |
| - case PROJECTION: |
| SetMode(INVISIBLE); |
| break; |
| case INVISIBLE: |
| @@ -560,28 +398,22 @@ void TouchObserverHUD::ChangeToNextMode() { |
| } |
| } |
| -void TouchObserverHUD::Clear() { |
| - if (widget_->IsVisible()) |
| - canvas_->Clear(); |
| - for (int i = 0; i < kMaxTouchPoints; ++i) |
| - touch_labels_[i]->SetText(string16()); |
| - label_container_->SetSize(label_container_->GetPreferredSize()); |
| +scoped_ptr<ListValue> TouchHudDebug::GetLogAsList() const { |
| + return touch_log_->GetAsList(); |
| } |
| -scoped_ptr<ListValue> TouchObserverHUD::GetLogAsList() const { |
| - return touch_log_->GetAsList(); |
| +void TouchHudDebug::Clear() { |
| + if (widget()->IsVisible()) { |
| + canvas_->Clear(); |
| + for (int i = 0; i < kMaxTouchPoints; ++i) |
| + touch_labels_[i]->SetText(string16()); |
| + label_container_->SetSize(label_container_->GetPreferredSize()); |
| + } |
| } |
| -void TouchObserverHUD::SetMode(Mode mode) { |
| +void TouchHudDebug::SetMode(Mode mode) { |
| if (mode_ == mode) |
| return; |
| - // When going out of projection mode, hide all active touch points. |
| - if (mode_ == PROJECTION) { |
| - for (std::map<int, TouchPointView*>::iterator iter = points_.begin(); |
| - iter != points_.end(); ++iter) |
| - iter->second->Remove(); |
| - points_.clear(); |
| - } |
| mode_ = mode; |
| switch (mode) { |
| case FULLSCREEN: |
| @@ -589,27 +421,22 @@ void TouchObserverHUD::SetMode(Mode mode) { |
| canvas_->SetVisible(true); |
| canvas_->SetScale(1); |
| canvas_->SchedulePaint(); |
| - widget_->Show(); |
| + widget()->Show(); |
| break; |
| case REDUCED_SCALE: |
| label_container_->SetVisible(true); |
| canvas_->SetVisible(true); |
| canvas_->SetScale(kReducedScale); |
| canvas_->SchedulePaint(); |
| - widget_->Show(); |
| - break; |
| - case PROJECTION: |
| - label_container_->SetVisible(false); |
| - canvas_->SetVisible(false); |
| - widget_->Show(); |
| + widget()->Show(); |
| break; |
| case INVISIBLE: |
| - widget_->Hide(); |
| + widget()->Hide(); |
| break; |
| } |
| } |
| -void TouchObserverHUD::UpdateTouchPointLabel(int index) { |
| +void TouchHudDebug::UpdateTouchPointLabel(int index) { |
| int trace_index = touch_log_->GetTraceIndex(index); |
| const TouchTrace& trace = touch_log_->traces()[trace_index]; |
| TouchTrace::const_reverse_iterator point = trace.log().rbegin(); |
| @@ -628,104 +455,34 @@ void TouchObserverHUD::UpdateTouchPointLabel(int index) { |
| touch_labels_[index]->SetText(UTF8ToUTF16(string)); |
| } |
| -void TouchObserverHUD::OnTouchEvent(ui::TouchEvent* event) { |
| +void TouchHudDebug::OnTouchEvent(ui::TouchEvent* event) { |
| if (event->touch_id() >= kMaxTouchPoints) |
| return; |
| touch_log_->AddTouchPoint(*event); |
| canvas_->TouchPointAdded(event->touch_id()); |
| - |
| - if (mode_ == PROJECTION) { |
| - 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); |
| - } |
| - } |
| - } |
| - |
| UpdateTouchPointLabel(event->touch_id()); |
| label_container_->SetSize(label_container_->GetPreferredSize()); |
| } |
| -void TouchObserverHUD::OnWidgetDestroying(views::Widget* widget) { |
| - DCHECK_EQ(widget, widget_); |
| - delete this; |
| -} |
| +void TouchHudDebug::OnDisplayBoundsChanged(const gfx::Display& display) { |
| + TouchObserverHUD::OnDisplayBoundsChanged(display); |
| -void TouchObserverHUD::OnDisplayBoundsChanged(const gfx::Display& display) { |
| - if (display.id() != display_id_) |
| + if (display.id() != display_id()) |
| return; |
| const gfx::Size& size = display.size(); |
| - widget_->SetSize(size); |
| canvas_->SetSize(size); |
| label_container_->SetY(size.height() / kReducedScale); |
| } |
| -void TouchObserverHUD::OnDisplayAdded(const gfx::Display& new_display) {} |
| - |
| -void TouchObserverHUD::OnDisplayRemoved(const gfx::Display& old_display) { |
| - if (old_display.id() != display_id_) |
| - return; |
| - widget_->CloseNow(); |
| -} |
| - |
| -#if defined(OS_CHROMEOS) |
| -void TouchObserverHUD::OnDisplayModeChanged() { |
| - // Clear touch HUD for any change in display mode (single, dual extended, dual |
| - // mirrored, ...). |
| - Clear(); |
| +void TouchHudDebug::SetHudForRootWindowController( |
| + RootWindowController* controller) { |
| + controller->set_touch_hud_debug(this); |
| } |
| -#endif // defined(OS_CHROMEOS) |
| - |
| -void TouchObserverHUD::OnDisplayConfigurationChanging() { |
| - if (!root_window_) |
| - return; |
| - |
| - root_window_->RemovePreTargetHandler(this); |
| - |
| - RootWindowController* controller = GetRootWindowController(root_window_); |
| - controller->set_touch_observer_hud(NULL); |
| - |
| - views::Widget::ReparentNativeView( |
| - widget_->GetNativeView(), |
| - Shell::GetContainer(root_window_, |
| - internal::kShellWindowId_UnparentedControlContainer)); |
| - |
| - root_window_ = NULL; |
| -} |
| - |
| -void TouchObserverHUD::OnDisplayConfigurationChanged() { |
| - if (root_window_) |
| - return; |
| - |
| - root_window_ = Shell::GetInstance()->display_controller()-> |
| - GetRootWindowForDisplayId(display_id_); |
| - |
| - views::Widget::ReparentNativeView( |
| - widget_->GetNativeView(), |
| - Shell::GetContainer(root_window_, |
| - internal::kShellWindowId_OverlayContainer)); |
| - |
| - RootWindowController* controller = GetRootWindowController(root_window_); |
| - controller->set_touch_observer_hud(this); |
| - root_window_->AddPreTargetHandler(this); |
| +void TouchHudDebug::UnsetHudForRootWindowController( |
| + RootWindowController* controller) { |
| + controller->set_touch_hud_debug(NULL); |
| } |
| } // namespace internal |