Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" | 5 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/android/vr_shell/textures/url_bar_texture.h" | 8 #include "chrome/browser/android/vr_shell/textures/url_bar_texture.h" |
| 9 | 9 |
| 10 namespace vr_shell { | 10 namespace vr_shell { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // We will often get spammed with many updates. We will also get security and | 14 // We will often get spammed with many updates. We will also get security and |
| 15 // url updates out of sync. To address both these problems, we will hang onto | 15 // url updates out of sync. To address both these problems, we will hang onto |
| 16 // dirtyness for |kUpdateDelay| before updating our texture to reduce visual | 16 // dirtyness for |kUpdateDelay| before updating our texture to reduce visual |
| 17 // churn. | 17 // churn. |
| 18 constexpr int64_t kUpdateDelayMS = 50; | 18 constexpr int64_t kUpdateDelayMS = 50; |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 UrlBar::UrlBar(int preferred_width, | 22 UrlBar::UrlBar(int preferred_width, |
| 23 const base::Callback<void()>& back_button_callback, | |
| 24 const base::Callback<void()>& security_icon_callback, | |
| 23 const base::Callback<void(UiUnsupportedMode)>& failure_callback) | 25 const base::Callback<void(UiUnsupportedMode)>& failure_callback) |
| 24 : TexturedElement(preferred_width), | 26 : TexturedElement(preferred_width), |
| 25 texture_(base::MakeUnique<UrlBarTexture>(failure_callback)) {} | 27 texture_(base::MakeUnique<UrlBarTexture>(failure_callback)), |
| 28 back_button_callback_(back_button_callback), | |
| 29 security_icon_callback_(security_icon_callback) {} | |
| 26 | 30 |
| 27 UrlBar::~UrlBar() = default; | 31 UrlBar::~UrlBar() = default; |
| 28 | 32 |
| 29 void UrlBar::UpdateTexture() { | 33 void UrlBar::UpdateTexture() { |
| 30 TexturedElement::UpdateTexture(); | 34 TexturedElement::UpdateTexture(); |
| 31 last_update_time_ = last_begin_frame_time_; | 35 last_update_time_ = last_begin_frame_time_; |
| 32 } | 36 } |
| 33 | 37 |
| 34 UiTexture* UrlBar::GetTexture() const { | 38 UiTexture* UrlBar::GetTexture() const { |
| 35 return texture_.get(); | 39 return texture_.get(); |
| 36 } | 40 } |
| 37 | 41 |
| 38 void UrlBar::OnHoverEnter(const gfx::PointF& position) { | 42 void UrlBar::OnHoverEnter(const gfx::PointF& position) { |
| 39 OnStateUpdated(position); | 43 OnStateUpdated(position); |
| 40 } | 44 } |
| 41 | 45 |
| 42 void UrlBar::OnHoverLeave() { | 46 void UrlBar::OnHoverLeave() { |
| 43 OnStateUpdated(gfx::PointF(std::numeric_limits<float>::max(), | 47 OnStateUpdated(gfx::PointF(std::numeric_limits<float>::max(), |
| 44 std::numeric_limits<float>::max())); | 48 std::numeric_limits<float>::max())); |
| 45 } | 49 } |
| 46 | 50 |
| 47 void UrlBar::OnMove(const gfx::PointF& position) { | 51 void UrlBar::OnMove(const gfx::PointF& position) { |
| 48 OnStateUpdated(position); | 52 OnStateUpdated(position); |
| 49 } | 53 } |
| 50 | 54 |
| 51 void UrlBar::OnButtonDown(const gfx::PointF& position) { | 55 void UrlBar::OnButtonDown(const gfx::PointF& position) { |
| 52 if (texture_->HitsBackButton(position)) | 56 if (texture_->HitsBackButton(position)) |
| 53 down_ = true; | 57 down_ = true; |
| 58 if (texture_->HitsSecurityIcon(position)) | |
|
cjgrant
2017/06/05 17:33:53
else if?
ymalik
2017/06/05 20:02:42
Done.
| |
| 59 security_icon_down_ = true; | |
| 54 OnStateUpdated(position); | 60 OnStateUpdated(position); |
| 55 } | 61 } |
| 56 | 62 |
| 57 void UrlBar::OnButtonUp(const gfx::PointF& position) { | 63 void UrlBar::OnButtonUp(const gfx::PointF& position) { |
| 58 down_ = false; | 64 down_ = false; |
| 59 OnStateUpdated(position); | 65 OnStateUpdated(position); |
| 60 if (texture_->HitsBackButton(position)) | 66 if (texture_->HitsBackButton(position)) |
| 61 back_button_callback_.Run(); | 67 back_button_callback_.Run(); |
| 68 else if (security_icon_down_ && texture_->HitsSecurityIcon(position)) { | |
| 69 security_icon_callback_.Run(); | |
| 70 } | |
| 71 security_icon_down_ = false; | |
| 62 } | 72 } |
| 63 | 73 |
| 64 bool UrlBar::HitTest(const gfx::PointF& position) const { | 74 bool UrlBar::HitTest(const gfx::PointF& position) const { |
| 65 return texture_->HitsUrlBar(position) || texture_->HitsBackButton(position); | 75 return texture_->HitsUrlBar(position) || texture_->HitsBackButton(position); |
| 66 } | 76 } |
| 67 | 77 |
| 68 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) { | 78 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) { |
| 69 last_begin_frame_time_ = begin_frame_time; | 79 last_begin_frame_time_ = begin_frame_time; |
| 70 if (enabled_ && texture_->dirty()) { | 80 if (enabled_ && texture_->dirty()) { |
| 71 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds(); | 81 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 84 } | 94 } |
| 85 | 95 |
| 86 void UrlBar::SetHistoryButtonsEnabled(bool can_go_back) { | 96 void UrlBar::SetHistoryButtonsEnabled(bool can_go_back) { |
| 87 texture_->SetHistoryButtonsEnabled(can_go_back); | 97 texture_->SetHistoryButtonsEnabled(can_go_back); |
| 88 } | 98 } |
| 89 | 99 |
| 90 void UrlBar::SetSecurityLevel(security_state::SecurityLevel level) { | 100 void UrlBar::SetSecurityLevel(security_state::SecurityLevel level) { |
| 91 texture_->SetSecurityLevel(level); | 101 texture_->SetSecurityLevel(level); |
| 92 } | 102 } |
| 93 | 103 |
| 94 void UrlBar::SetBackButtonCallback(const base::Callback<void()>& callback) { | |
| 95 back_button_callback_ = callback; | |
| 96 } | |
| 97 | |
| 98 void UrlBar::OnStateUpdated(const gfx::PointF& position) { | 104 void UrlBar::OnStateUpdated(const gfx::PointF& position) { |
| 99 const bool hovered = texture_->HitsBackButton(position); | 105 const bool hovered = texture_->HitsBackButton(position); |
| 100 const bool pressed = hovered ? down_ : false; | 106 const bool pressed = hovered ? down_ : false; |
| 101 | 107 |
| 102 texture_->SetHovered(hovered); | 108 texture_->SetHovered(hovered); |
| 103 texture_->SetPressed(pressed); | 109 texture_->SetPressed(pressed); |
| 104 UpdateTexture(); | 110 UpdateTexture(); |
| 105 } | 111 } |
| 106 | 112 |
| 107 } // namespace vr_shell | 113 } // namespace vr_shell |
| OLD | NEW |