| 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/textures/url_bar_texture.h" | 5 #include "chrome/browser/android/vr_shell/textures/url_bar_texture.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "cc/paint/skia_paint_canvas.h" | 8 #include "cc/paint/skia_paint_canvas.h" |
| 9 #include "components/security_state/core/security_state.h" | 9 #include "components/security_state/core/security_state.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 set_dirty(); | 132 set_dirty(); |
| 133 hovered_ = hovered; | 133 hovered_ = hovered; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void UrlBarTexture::SetPressed(bool pressed) { | 136 void UrlBarTexture::SetPressed(bool pressed) { |
| 137 if (pressed_ != pressed) | 137 if (pressed_ != pressed) |
| 138 set_dirty(); | 138 set_dirty(); |
| 139 pressed_ = pressed; | 139 pressed_ = pressed; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void UrlBarTexture::SetIncognito(bool incognito) { |
| 143 if (incognito_ != incognito) |
| 144 set_dirty(); |
| 145 incognito_ = incognito; |
| 146 } |
| 147 |
| 148 SkColor UrlBarTexture::AdjustColorForIncognito(SkColor c) const { |
| 149 if (incognito_) |
| 150 return SkColorSetA(c, 255); |
| 151 return c; |
| 152 } |
| 153 |
| 142 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { | 154 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { |
| 143 size_.set_height(texture_size.height()); | 155 size_.set_height(texture_size.height()); |
| 144 size_.set_width(texture_size.width()); | 156 size_.set_width(texture_size.width()); |
| 145 | 157 |
| 146 canvas->save(); | 158 canvas->save(); |
| 147 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); | 159 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); |
| 148 | 160 |
| 149 // Make a gfx canvas to support utility drawing methods. | 161 // Make a gfx canvas to support utility drawing methods. |
| 150 cc::SkiaPaintCanvas paint_canvas(canvas); | 162 cc::SkiaPaintCanvas paint_canvas(canvas); |
| 151 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); | 163 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); |
| 152 | 164 |
| 153 // Back button area. | 165 // Back button area. |
| 154 SkRRect round_rect; | 166 SkRRect round_rect; |
| 155 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; | 167 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; |
| 156 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; | 168 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; |
| 157 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); | 169 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); |
| 158 SkColor color = hovered_ ? kBackgroundHover : kBackground; | 170 SkColor color = hovered_ ? kBackgroundHover : kBackground; |
| 159 color = pressed_ ? kBackgroundDown : color; | 171 color = pressed_ ? kBackgroundDown : color; |
| 160 SkPaint paint; | 172 SkPaint paint; |
| 161 paint.setColor(color); | 173 paint.setColor(AdjustColorForIncognito(color)); |
| 162 canvas->drawRRect(round_rect, paint); | 174 canvas->drawRRect(round_rect, paint); |
| 163 | 175 |
| 164 // URL area. | 176 // URL area. |
| 165 paint.setColor(kBackground); | 177 paint.setColor(AdjustColorForIncognito(kBackground)); |
| 166 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; | 178 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; |
| 167 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); | 179 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); |
| 168 canvas->drawRRect(round_rect, paint); | 180 canvas->drawRRect(round_rect, paint); |
| 169 | 181 |
| 170 // Back button / URL separator vertical line. | 182 // Back button / URL separator vertical line. |
| 171 paint.setColor(kSeparatorColor); | 183 paint.setColor(kSeparatorColor); |
| 172 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), | 184 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), |
| 173 paint); | 185 paint); |
| 174 | 186 |
| 175 // Back button icon. | 187 // Back button icon. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 234 |
| 223 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 235 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 224 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 236 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 225 } | 237 } |
| 226 | 238 |
| 227 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 239 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 228 return size_; | 240 return size_; |
| 229 } | 241 } |
| 230 | 242 |
| 231 } // namespace vr_shell | 243 } // namespace vr_shell |
| OLD | NEW |