OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/touch_handle_drawable_aura.h" |
| 6 |
| 7 #include "ui/aura/window.h" |
| 8 #include "ui/aura/window_targeter.h" |
| 9 #include "ui/base/cursor/cursor.h" |
| 10 #include "ui/base/hit_test.h" |
| 11 #include "ui/events/event.h" |
| 12 #include "ui/gfx/canvas.h" |
| 13 |
| 14 namespace content { |
| 15 namespace { |
| 16 |
| 17 class TouchHandleDrawableAuraTargeter : public aura::WindowTargeter { |
| 18 protected: |
| 19 virtual bool EventLocationInsideBounds( |
| 20 ui::EventTarget* target, |
| 21 const ui::LocatedEvent& event) const override; |
| 22 }; |
| 23 |
| 24 bool TouchHandleDrawableAuraTargeter::EventLocationInsideBounds( |
| 25 ui::EventTarget* target, |
| 26 const ui::LocatedEvent& event) const { |
| 27 return false; |
| 28 } |
| 29 |
| 30 } |
| 31 |
| 32 TouchHandleDrawableAura::TouchHandleDrawableAura(aura::Window* parent) |
| 33 : window_(new aura::Window(this)), |
| 34 enabled_(false), |
| 35 alpha_(0) { |
| 36 window_->SetTransparent(true); |
| 37 window_->Init(aura::WINDOW_LAYER_TEXTURED); |
| 38 window_->set_owned_by_parent(false); |
| 39 window_->SetEventTargeter( |
| 40 scoped_ptr<ui::EventTargeter>(new TouchHandleDrawableAuraTargeter)); |
| 41 parent->AddChild(window_.get()); |
| 42 } |
| 43 |
| 44 TouchHandleDrawableAura::~TouchHandleDrawableAura() { |
| 45 } |
| 46 |
| 47 void TouchHandleDrawableAura::SetEnabled(bool enabled) { |
| 48 if (enabled == enabled_) |
| 49 return; |
| 50 |
| 51 enabled_ = enabled; |
| 52 bool visible = alpha_ > 0; // XXX: float comparison |
| 53 if (enabled_ && visible) |
| 54 window_->Show(); |
| 55 else |
| 56 window_->Hide(); |
| 57 } |
| 58 |
| 59 void TouchHandleDrawableAura::SetOrientation( |
| 60 TouchHandleOrientation orientation) { |
| 61 } |
| 62 |
| 63 void TouchHandleDrawableAura::SetAlpha(float alpha) { |
| 64 if (alpha == alpha_) // XXX: float comparison |
| 65 return; |
| 66 |
| 67 alpha_ = alpha; |
| 68 window_->layer()->SetOpacity(alpha_); |
| 69 bool visible = alpha_ > 0; // XXX: float comparison |
| 70 if (enabled_ && visible) |
| 71 window_->Show(); |
| 72 else |
| 73 window_->Hide(); |
| 74 } |
| 75 |
| 76 void TouchHandleDrawableAura::SetFocus(const gfx::PointF& position) { |
| 77 window_->SetBounds(gfx::Rect(position.x() - 10, position.y(), 20, 50)); |
| 78 } |
| 79 |
| 80 bool TouchHandleDrawableAura::IntersectsWith(const gfx::RectF& rect) const { |
| 81 gfx::RectF r(window_->bounds()); |
| 82 r.Inset(-25, -25); |
| 83 return r.Intersects(rect); |
| 84 } |
| 85 |
| 86 gfx::Size TouchHandleDrawableAura::GetMinimumSize() const { |
| 87 return gfx::Size(20, 50); |
| 88 } |
| 89 |
| 90 gfx::Size TouchHandleDrawableAura::GetMaximumSize() const { |
| 91 return gfx::Size(20, 50); |
| 92 } |
| 93 |
| 94 void TouchHandleDrawableAura::OnBoundsChanged(const gfx::Rect& old_bounds, |
| 95 const gfx::Rect& new_bounds) { |
| 96 } |
| 97 |
| 98 gfx::NativeCursor TouchHandleDrawableAura::GetCursor(const gfx::Point& point) { |
| 99 return gfx::kNullCursor; |
| 100 } |
| 101 |
| 102 int TouchHandleDrawableAura::GetNonClientComponent( |
| 103 const gfx::Point& point) const { |
| 104 return HTCLIENT; |
| 105 } |
| 106 |
| 107 bool TouchHandleDrawableAura::ShouldDescendIntoChildForEventHandling( |
| 108 aura::Window* child, |
| 109 const gfx::Point& location) { |
| 110 return false; |
| 111 } |
| 112 |
| 113 bool TouchHandleDrawableAura::CanFocus() { |
| 114 return false; |
| 115 } |
| 116 |
| 117 void TouchHandleDrawableAura::OnCaptureLost() { |
| 118 } |
| 119 |
| 120 void TouchHandleDrawableAura::OnPaint(gfx::Canvas* canvas) { |
| 121 canvas->DrawColor(SK_ColorYELLOW); |
| 122 } |
| 123 |
| 124 void TouchHandleDrawableAura::OnDeviceScaleFactorChanged( |
| 125 float device_scale_factor) { |
| 126 } |
| 127 |
| 128 void TouchHandleDrawableAura::OnWindowDestroying(aura::Window* window) { |
| 129 } |
| 130 |
| 131 void TouchHandleDrawableAura::OnWindowDestroyed(aura::Window* window) { |
| 132 } |
| 133 |
| 134 void TouchHandleDrawableAura::OnWindowTargetVisibilityChanged(bool visible) { |
| 135 } |
| 136 |
| 137 bool TouchHandleDrawableAura::HasHitTestMask() const { |
| 138 return false; |
| 139 } |
| 140 |
| 141 void TouchHandleDrawableAura::GetHitTestMask(gfx::Path* mask) const { |
| 142 } |
| 143 |
| 144 } |
OLD | NEW |