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

Side by Side Diff: chrome/browser/chromeos/login/helper.cc

Issue 5709001: Place the spinner in the right corner of the controls window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/chromeos/login
Patch Set: code review Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/chromeos/login/helper.h" 5 #include "chrome/browser/chromeos/login/helper.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "chrome/browser/google/google_util.h" 8 #include "chrome/browser/google/google_util.h"
9 #include "gfx/canvas_skia.h" 9 #include "gfx/canvas_skia.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "grit/theme_resources.h" 11 #include "grit/theme_resources.h"
12 #include "third_party/skia/include/effects/SkGradientShader.h" 12 #include "third_party/skia/include/effects/SkGradientShader.h"
13 #include "views/controls/button/menu_button.h" 13 #include "views/controls/button/menu_button.h"
14 #include "views/controls/button/native_button.h" 14 #include "views/controls/button/native_button.h"
15 #include "views/controls/label.h" 15 #include "views/controls/label.h"
16 #include "views/controls/textfield/textfield.h" 16 #include "views/controls/textfield/textfield.h"
17 #include "views/controls/throbber.h" 17 #include "views/controls/throbber.h"
18 #include "views/painter.h" 18 #include "views/painter.h"
19 #include "views/screen.h" 19 #include "views/screen.h"
20 #include "views/widget/widget.h"
20 21
21 namespace chromeos { 22 namespace chromeos {
22 23
23 namespace { 24 namespace {
24 25
25 // Time in ms per throbber frame. 26 // Time in ms per throbber frame.
26 const int kThrobberFrameMs = 60; 27 const int kThrobberFrameMs = 60;
27 28
28 // Time in ms before smoothed throbber is shown. 29 // Time in ms before smoothed throbber is shown.
29 const int kThrobberStartDelayMs = 500; 30 const int kThrobberStartDelayMs = 500;
(...skipping 30 matching lines...) Expand all
60 s->unref(); 61 s->unref();
61 canvas->AsCanvasSkia()->drawRect(rect, paint); 62 canvas->AsCanvasSkia()->drawRect(rect, paint);
62 } 63 }
63 64
64 private: 65 private:
65 DISALLOW_COPY_AND_ASSIGN(BackgroundPainter); 66 DISALLOW_COPY_AND_ASSIGN(BackgroundPainter);
66 }; 67 };
67 68
68 } // namespace 69 } // namespace
69 70
71 ThrobberManager::ThrobberManager() : throbber_widget_(NULL) {
72 }
73
74 ThrobberManager::~ThrobberManager() {
75 StopAndClose();
76 }
77
78 void ThrobberManager::CreateAndStart(views::Widget* host,
79 views::Throbber* throbber,
80 int right_margin) {
81 gfx::Rect host_bounds;
82 host->GetBounds(&host_bounds, false);
83 gfx::Rect bounds(throbber->GetPreferredSize());
84 bounds.set_x(host_bounds.width() - right_margin - bounds.width());
85 bounds.set_y((host_bounds.height() - bounds.height()) / 2);
86 CreateAndStart(host, throbber, bounds);
87 }
88
89 void ThrobberManager::CreateAndStart(views::Widget* host,
90 views::Throbber* throbber,
91 const gfx::Rect& relative_bounds) {
92 // Close the previously opened throbber (if any).
93 StopAndClose();
94
95 throbber_widget_ =
96 views::Widget::CreatePopupWidget(views::Widget::Transparent,
97 views::Widget::NotAcceptEvents,
98 views::Widget::DeleteOnDestroy,
99 views::Widget::DontMirrorOriginInRTL);
100 gfx::Rect host_bounds;
101 host->GetBounds(&host_bounds, false);
102 gfx::Rect bounds = relative_bounds;
103 bounds.Offset(host_bounds.origin());
104 throbber_widget_->InitWithWidget(host, bounds);
105 throbber_widget_->SetContentsView(throbber);
106 throbber_widget_->Show();
107 throbber->Start();
108 }
109
110 void ThrobberManager::StopAndClose() {
111 if (throbber_widget_) {
112 throbber_widget_->Close();
113 throbber_widget_ = NULL;
114 }
115 }
116
70 views::Throbber* CreateDefaultSmoothedThrobber() { 117 views::Throbber* CreateDefaultSmoothedThrobber() {
71 views::SmoothedThrobber* throbber = 118 views::SmoothedThrobber* throbber =
72 new views::SmoothedThrobber(kThrobberFrameMs); 119 new views::SmoothedThrobber(kThrobberFrameMs);
73 throbber->SetFrames( 120 throbber->SetFrames(
74 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER)); 121 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER));
75 throbber->set_start_delay_ms(kThrobberStartDelayMs); 122 throbber->set_start_delay_ms(kThrobberStartDelayMs);
76 return throbber; 123 return throbber;
77 } 124 }
78 125
79 views::Throbber* CreateDefaultThrobber() { 126 views::Throbber* CreateDefaultThrobber() {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 gfx::Size preferred_size = NativeButton::GetPreferredSize(); 178 gfx::Size preferred_size = NativeButton::GetPreferredSize();
132 // Set minimal width. 179 // Set minimal width.
133 if (preferred_size.width() < kButtonMinWidth) 180 if (preferred_size.width() < kButtonMinWidth)
134 preferred_size.set_width(kButtonMinWidth); 181 preferred_size.set_width(kButtonMinWidth);
135 return preferred_size; 182 return preferred_size;
136 } 183 }
137 184
138 } // namespace login 185 } // namespace login
139 186
140 } // namespace chromeos 187 } // namespace chromeos
141
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698