Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/android/vr_shell/ui_elements/url_bar.cc

Issue 2913633002: [vr] Clicking on the security icon should prompt the user to bail out of VR (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 else if (texture_->HitsSecurityIcon(position))
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 (can_go_back_ && texture_->HitsBackButton(position)) 66 if (can_go_back_ && 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 security_icon_down_ = false;
62 } 71 }
63 72
64 bool UrlBar::HitTest(const gfx::PointF& position) const { 73 bool UrlBar::HitTest(const gfx::PointF& position) const {
65 return texture_->HitsUrlBar(position) || texture_->HitsBackButton(position); 74 return texture_->HitsUrlBar(position) || texture_->HitsBackButton(position);
66 } 75 }
67 76
68 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) { 77 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) {
69 last_begin_frame_time_ = begin_frame_time; 78 last_begin_frame_time_ = begin_frame_time;
70 if (enabled_ && texture_->dirty()) { 79 if (enabled_ && texture_->dirty()) {
71 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds(); 80 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds();
(...skipping 13 matching lines...) Expand all
85 94
86 void UrlBar::SetHistoryButtonsEnabled(bool can_go_back) { 95 void UrlBar::SetHistoryButtonsEnabled(bool can_go_back) {
87 can_go_back_ = can_go_back; 96 can_go_back_ = can_go_back;
88 texture_->SetHistoryButtonsEnabled(can_go_back_); 97 texture_->SetHistoryButtonsEnabled(can_go_back_);
89 } 98 }
90 99
91 void UrlBar::SetSecurityLevel(security_state::SecurityLevel level) { 100 void UrlBar::SetSecurityLevel(security_state::SecurityLevel level) {
92 texture_->SetSecurityLevel(level); 101 texture_->SetSecurityLevel(level);
93 } 102 }
94 103
95 void UrlBar::SetBackButtonCallback(const base::Callback<void()>& callback) {
96 back_button_callback_ = callback;
97 }
98
99 void UrlBar::OnStateUpdated(const gfx::PointF& position) { 104 void UrlBar::OnStateUpdated(const gfx::PointF& position) {
100 const bool hovered = texture_->HitsBackButton(position); 105 const bool hovered = texture_->HitsBackButton(position);
101 const bool pressed = hovered ? down_ : false; 106 const bool pressed = hovered ? down_ : false;
102 107
103 texture_->SetHovered(hovered); 108 texture_->SetHovered(hovered);
104 texture_->SetPressed(pressed); 109 texture_->SetPressed(pressed);
105 UpdateTexture(); 110 UpdateTexture();
106 } 111 }
107 112
108 } // namespace vr_shell 113 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_elements/url_bar.h ('k') | chrome/browser/android/vr_shell/ui_scene.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698