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 { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 void UrlBar::UpdateTexture() { | 28 void UrlBar::UpdateTexture() { |
| 29 TexturedElement::UpdateTexture(); | 29 TexturedElement::UpdateTexture(); |
| 30 last_update_time_ = last_begin_frame_time_; | 30 last_update_time_ = last_begin_frame_time_; |
| 31 } | 31 } |
| 32 | 32 |
| 33 UiTexture* UrlBar::GetTexture() const { | 33 UiTexture* UrlBar::GetTexture() const { |
| 34 return texture_.get(); | 34 return texture_.get(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void UrlBar::OnHoverEnter(const gfx::PointF& position) { | 37 void UrlBar::OnHoverEnter(const gfx::PointF& position) { |
| 38 if (!texture_->SetDrawFlags(UrlBarTexture::FLAG_HOVER)) | 38 OnStateUpdated(position); |
| 39 return; | |
| 40 UpdateTexture(); | |
| 41 } | 39 } |
| 42 | 40 |
| 43 void UrlBar::OnHoverLeave() { | 41 void UrlBar::OnHoverLeave() { |
| 44 if (!texture_->SetDrawFlags(0)) | 42 OnStateUpdated(gfx::PointF(-1000, -1000)); |
|
cjgrant
2017/05/16 14:07:23
Were you okay with the numeric limits value? lowes
mthiesse
2017/05/16 18:11:02
Whoops missed this for the URL bar.
| |
| 45 return; | 43 } |
| 46 UpdateTexture(); | 44 |
| 45 void UrlBar::OnMove(const gfx::PointF& position) { | |
| 46 OnStateUpdated(position); | |
| 47 } | |
| 48 | |
| 49 void UrlBar::OnButtonDown(const gfx::PointF& position) { | |
| 50 if (texture_->HitsBackButton(position)) | |
| 51 down_ = true; | |
| 52 OnStateUpdated(position); | |
| 47 } | 53 } |
| 48 | 54 |
| 49 void UrlBar::OnButtonUp(const gfx::PointF& position) { | 55 void UrlBar::OnButtonUp(const gfx::PointF& position) { |
| 50 back_button_callback_.Run(); | 56 down_ = false; |
| 57 OnStateUpdated(position); | |
| 58 if (texture_->HitsBackButton(position)) | |
| 59 back_button_callback_.Run(); | |
| 60 } | |
| 61 | |
| 62 bool UrlBar::HitTest(const gfx::PointF& position) const { | |
| 63 return texture_->HitsURLBar(position) || texture_->HitsBackButton(position); | |
| 51 } | 64 } |
| 52 | 65 |
| 53 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) { | 66 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) { |
| 54 last_begin_frame_time_ = begin_frame_time; | 67 last_begin_frame_time_ = begin_frame_time; |
| 55 if (enabled_ && texture_->dirty()) { | 68 if (enabled_ && texture_->dirty()) { |
| 56 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds(); | 69 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds(); |
| 57 if (delta_ms > kUpdateDelayMS) | 70 if (delta_ms > kUpdateDelayMS) |
| 58 UpdateTexture(); | 71 UpdateTexture(); |
| 59 } | 72 } |
| 60 } | 73 } |
| 61 | 74 |
| 62 void UrlBar::SetEnabled(bool enabled) { | 75 void UrlBar::SetEnabled(bool enabled) { |
| 63 enabled_ = enabled; | 76 enabled_ = enabled; |
| 64 set_visible(enabled); | 77 set_visible(enabled); |
| 65 } | 78 } |
| 66 | 79 |
| 67 void UrlBar::SetURL(const GURL& gurl) { | 80 void UrlBar::SetURL(const GURL& gurl) { |
| 68 texture_->SetURL(gurl); | 81 texture_->SetURL(gurl); |
| 69 } | 82 } |
| 70 | 83 |
| 71 void UrlBar::SetSecurityLevel(int level) { | 84 void UrlBar::SetSecurityLevel(int level) { |
| 72 texture_->SetSecurityLevel(level); | 85 texture_->SetSecurityLevel(level); |
| 73 } | 86 } |
| 74 | 87 |
| 75 void UrlBar::SetBackButtonCallback(const base::Callback<void()>& callback) { | 88 void UrlBar::SetBackButtonCallback(const base::Callback<void()>& callback) { |
| 76 back_button_callback_ = callback; | 89 back_button_callback_ = callback; |
| 77 } | 90 } |
| 78 | 91 |
| 92 void UrlBar::OnStateUpdated(const gfx::PointF& position) { | |
| 93 bool hitting = texture_->HitsBackButton(position); | |
| 94 bool down = hitting ? down_ : false; | |
| 95 | |
| 96 int flags = hitting ? UrlBarTexture::FLAG_BACK_HOVER : 0; | |
| 97 flags |= down ? UrlBarTexture::FLAG_BACK_DOWN : 0; | |
| 98 if (!texture_->SetDrawFlags(flags)) | |
| 99 return; | |
| 100 UpdateTexture(); | |
| 101 } | |
| 102 | |
| 79 } // namespace vr_shell | 103 } // namespace vr_shell |
| OLD | NEW |