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

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: . 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();
(...skipping 16 matching lines...) Expand all
52 if (texture_->HitsBackButton(position)) 56 if (texture_->HitsBackButton(position))
53 down_ = true; 57 down_ = true;
54 OnStateUpdated(position); 58 OnStateUpdated(position);
55 } 59 }
56 60
57 void UrlBar::OnButtonUp(const gfx::PointF& position) { 61 void UrlBar::OnButtonUp(const gfx::PointF& position) {
58 down_ = false; 62 down_ = false;
59 OnStateUpdated(position); 63 OnStateUpdated(position);
60 if (texture_->HitsBackButton(position)) 64 if (texture_->HitsBackButton(position))
61 back_button_callback_.Run(); 65 back_button_callback_.Run();
66 if (texture_->HitsSecurityIcon(position)) {
cjgrant 2017/06/02 04:16:36 Same comment as earlier on down/up on the button.
67 security_icon_callback_.Run();
68 }
62 } 69 }
63 70
64 bool UrlBar::HitTest(const gfx::PointF& position) const { 71 bool UrlBar::HitTest(const gfx::PointF& position) const {
65 return texture_->HitsUrlBar(position) || texture_->HitsBackButton(position); 72 return texture_->HitsUrlBar(position) || texture_->HitsBackButton(position);
66 } 73 }
67 74
68 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) { 75 void UrlBar::OnBeginFrame(const base::TimeTicks& begin_frame_time) {
69 last_begin_frame_time_ = begin_frame_time; 76 last_begin_frame_time_ = begin_frame_time;
70 if (enabled_ && texture_->dirty()) { 77 if (enabled_ && texture_->dirty()) {
71 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds(); 78 int64_t delta_ms = (begin_frame_time - last_update_time_).InMilliseconds();
(...skipping 12 matching lines...) Expand all
84 } 91 }
85 92
86 void UrlBar::SetHistoryButtonsEnabled(bool can_go_back) { 93 void UrlBar::SetHistoryButtonsEnabled(bool can_go_back) {
87 texture_->SetHistoryButtonsEnabled(can_go_back); 94 texture_->SetHistoryButtonsEnabled(can_go_back);
88 } 95 }
89 96
90 void UrlBar::SetSecurityLevel(security_state::SecurityLevel level) { 97 void UrlBar::SetSecurityLevel(security_state::SecurityLevel level) {
91 texture_->SetSecurityLevel(level); 98 texture_->SetSecurityLevel(level);
92 } 99 }
93 100
94 void UrlBar::SetBackButtonCallback(const base::Callback<void()>& callback) {
95 back_button_callback_ = callback;
96 }
97
98 void UrlBar::OnStateUpdated(const gfx::PointF& position) { 101 void UrlBar::OnStateUpdated(const gfx::PointF& position) {
99 const bool hovered = texture_->HitsBackButton(position); 102 const bool hovered = texture_->HitsBackButton(position);
100 const bool pressed = hovered ? down_ : false; 103 const bool pressed = hovered ? down_ : false;
101 104
102 texture_->SetHovered(hovered); 105 texture_->SetHovered(hovered);
103 texture_->SetPressed(pressed); 106 texture_->SetPressed(pressed);
104 UpdateTexture(); 107 UpdateTexture();
105 } 108 }
106 109
107 } // namespace vr_shell 110 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698