Commit 0120f33d authored by Wei Li's avatar Wei Li Committed by Commit Bot

Use label for text on lock view

Using label for the text drawn on a lock view would simplify and speed
up the painting procedure and some custom setting for the text drawing.
This is part of a larger effort to remove direct calls to
Canvas::DrawStringRect().

BUG=940802

Change-Id: I165d390ba5ac75942ae59bd460b823865793b60b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1532894Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Wei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642741}
parent 3bb2aa90
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/text_utils.h" #include "ui/gfx/text_utils.h"
#include "ui/views/controls/button/md_text_button.h" #include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/corewm/tooltip_controller.h" #include "ui/views/corewm/tooltip_controller.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
...@@ -26,8 +27,11 @@ class LockView : public views::WidgetDelegateView, ...@@ -26,8 +27,11 @@ class LockView : public views::WidgetDelegateView,
public views::ButtonListener { public views::ButtonListener {
public: public:
LockView() LockView()
: unlock_button_( : text_(new views::Label(base::ASCIIToUTF16("LOCKED!"))),
unlock_button_(
views::MdTextButton::Create(this, base::ASCIIToUTF16("Unlock"))) { views::MdTextButton::Create(this, base::ASCIIToUTF16("Unlock"))) {
text_->SetEnabledColor(SK_ColorRED);
AddChildView(text_);
AddChildView(unlock_button_); AddChildView(unlock_button_);
} }
~LockView() override = default; ~LockView() override = default;
...@@ -41,21 +45,22 @@ class LockView : public views::WidgetDelegateView, ...@@ -41,21 +45,22 @@ class LockView : public views::WidgetDelegateView,
// Overridden from views::View: // Overridden from views::View:
void OnPaint(gfx::Canvas* canvas) override { void OnPaint(gfx::Canvas* canvas) override {
canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW); canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
base::string16 text = base::ASCIIToUTF16("LOCKED!");
int string_width = gfx::GetStringWidth(text, font_list_);
canvas->DrawStringRect(text, font_list_, SK_ColorRED,
gfx::Rect((width() - string_width) / 2,
(height() - font_list_.GetHeight()) / 2,
string_width, font_list_.GetHeight()));
} }
void Layout() override { void Layout() override {
gfx::Rect bounds = GetLocalBounds(); gfx::Rect bounds = GetLocalBounds();
gfx::Size ts = text_->GetPreferredSize();
text_->SetBoundsRect(gfx::Rect((bounds.width() - ts.width()) / 2,
(bounds.height() - ts.height()) / 2,
ts.width(), ts.height()));
gfx::Size ps = unlock_button_->GetPreferredSize(); gfx::Size ps = unlock_button_->GetPreferredSize();
bounds.set_y(bounds.bottom() - ps.height() - 5); bounds.set_y(bounds.bottom() - ps.height() - 5);
bounds.set_x((bounds.width() - ps.width()) / 2); bounds.set_x((bounds.width() - ps.width()) / 2);
bounds.set_size(ps); bounds.set_size(ps);
unlock_button_->SetBoundsRect(bounds); unlock_button_->SetBoundsRect(bounds);
} }
void ViewHierarchyChanged( void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) override { const ViewHierarchyChangedDetails& details) override {
if (details.is_add && details.child == this) if (details.is_add && details.child == this)
...@@ -73,7 +78,7 @@ class LockView : public views::WidgetDelegateView, ...@@ -73,7 +78,7 @@ class LockView : public views::WidgetDelegateView,
GetWidget()->Close(); GetWidget()->Close();
} }
gfx::FontList font_list_; views::Label* text_;
views::Button* unlock_button_; views::Button* unlock_button_;
DISALLOW_COPY_AND_ASSIGN(LockView); DISALLOW_COPY_AND_ASSIGN(LockView);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment