| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 void UrlBar::OnButtonDown(const gfx::PointF& position) { | 51 void UrlBar::OnButtonDown(const gfx::PointF& position) { |
| 52 if (texture_->HitsBackButton(position)) | 52 if (texture_->HitsBackButton(position)) |
| 53 down_ = true; | 53 down_ = true; |
| 54 OnStateUpdated(position); | 54 OnStateUpdated(position); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void UrlBar::OnButtonUp(const gfx::PointF& position) { | 57 void UrlBar::OnButtonUp(const gfx::PointF& position) { |
| 58 down_ = false; | 58 down_ = false; |
| 59 OnStateUpdated(position); | 59 OnStateUpdated(position); |
| 60 if (texture_->HitsBackButton(position)) | 60 if (can_go_back_ && texture_->HitsBackButton(position)) |
| 61 back_button_callback_.Run(); | 61 back_button_callback_.Run(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool UrlBar::HitTest(const gfx::PointF& position) const { | 64 bool UrlBar::HitTest(const gfx::PointF& position) const { |
| 65 return texture_->HitsUrlBar(position) || texture_->HitsBackButton(position); | 65 return texture_->HitsUrlBar(position) || texture_->HitsBackButton(position); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) { | 68 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) { |
| 69 last_begin_frame_time_ = begin_frame_time; | 69 last_begin_frame_time_ = begin_frame_time; |
| 70 if (enabled_ && texture_->dirty()) { | 70 if (enabled_ && texture_->dirty()) { |
| 71 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds(); | 71 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds(); |
| 72 if (delta_ms > kUpdateDelayMS) | 72 if (delta_ms > kUpdateDelayMS) |
| 73 UpdateTexture(); | 73 UpdateTexture(); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void UrlBar::SetEnabled(bool enabled) { | 77 void UrlBar::SetEnabled(bool enabled) { |
| 78 enabled_ = enabled; | 78 enabled_ = enabled; |
| 79 set_visible(enabled); | 79 set_visible(enabled); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void UrlBar::SetURL(const GURL& gurl) { | 82 void UrlBar::SetURL(const GURL& gurl) { |
| 83 texture_->SetURL(gurl); | 83 texture_->SetURL(gurl); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void UrlBar::SetHistoryButtonsEnabled(bool can_go_back) { | 86 void UrlBar::SetHistoryButtonsEnabled(bool can_go_back) { |
| 87 texture_->SetHistoryButtonsEnabled(can_go_back); | 87 can_go_back_ = can_go_back; |
| 88 texture_->SetHistoryButtonsEnabled(can_go_back_); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void UrlBar::SetSecurityLevel(security_state::SecurityLevel level) { | 91 void UrlBar::SetSecurityLevel(security_state::SecurityLevel level) { |
| 91 texture_->SetSecurityLevel(level); | 92 texture_->SetSecurityLevel(level); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void UrlBar::SetBackButtonCallback(const base::Callback<void()>& callback) { | 95 void UrlBar::SetBackButtonCallback(const base::Callback<void()>& callback) { |
| 95 back_button_callback_ = callback; | 96 back_button_callback_ = callback; |
| 96 } | 97 } |
| 97 | 98 |
| 98 void UrlBar::OnStateUpdated(const gfx::PointF& position) { | 99 void UrlBar::OnStateUpdated(const gfx::PointF& position) { |
| 99 const bool hovered = texture_->HitsBackButton(position); | 100 const bool hovered = texture_->HitsBackButton(position); |
| 100 const bool pressed = hovered ? down_ : false; | 101 const bool pressed = hovered ? down_ : false; |
| 101 | 102 |
| 102 texture_->SetHovered(hovered); | 103 texture_->SetHovered(hovered); |
| 103 texture_->SetPressed(pressed); | 104 texture_->SetPressed(pressed); |
| 104 UpdateTexture(); | 105 UpdateTexture(); |
| 105 } | 106 } |
| 106 | 107 |
| 107 } // namespace vr_shell | 108 } // namespace vr_shell |
| OLD | NEW |