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

Side by Side Diff: chrome/browser/chromeos/notifications/balloon_view.cc

Issue 1055005: Refactor BalloonViewHost, removing a lot of duplicate code that crept into no... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/cocoa/notifications/balloon_view_host_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/notifications/balloon_view.h" 5 #include "chrome/browser/chromeos/notifications/balloon_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const std::wstring source_label_text = l10n_util::GetStringF( 65 const std::wstring source_label_text = l10n_util::GetStringF(
66 IDS_NOTIFICATION_BALLOON_SOURCE_LABEL, 66 IDS_NOTIFICATION_BALLOON_SOURCE_LABEL,
67 balloon->notification().display_source()); 67 balloon->notification().display_source());
68 const std::wstring options_text = 68 const std::wstring options_text =
69 l10n_util::GetString(IDS_NOTIFICATION_OPTIONS_MENU_LABEL); 69 l10n_util::GetString(IDS_NOTIFICATION_OPTIONS_MENU_LABEL);
70 const std::wstring dismiss_text = 70 const std::wstring dismiss_text =
71 l10n_util::GetString(IDS_NOTIFICATION_BALLOON_DISMISS_LABEL); 71 l10n_util::GetString(IDS_NOTIFICATION_BALLOON_DISMISS_LABEL);
72 balloon_ = balloon; 72 balloon_ = balloon;
73 73
74 html_contents_ = new BalloonViewHost(balloon); 74 html_contents_ = new BalloonViewHost(balloon);
75 AddChildView(html_contents_); 75 AddChildView(html_contents_->view());
76 if (controls_) { 76 if (controls_) {
77 close_button_ = new views::TextButton(this, dismiss_text); 77 close_button_ = new views::TextButton(this, dismiss_text);
78 close_button_->SetIcon(*rb.GetBitmapNamed(IDR_BALLOON_CLOSE)); 78 close_button_->SetIcon(*rb.GetBitmapNamed(IDR_BALLOON_CLOSE));
79 close_button_->SetHoverIcon(*rb.GetBitmapNamed(IDR_BALLOON_CLOSE_HOVER)); 79 close_button_->SetHoverIcon(*rb.GetBitmapNamed(IDR_BALLOON_CLOSE_HOVER));
80 close_button_->SetFont(rb.GetFont(ResourceBundle::SmallFont)); 80 close_button_->SetFont(rb.GetFont(ResourceBundle::SmallFont));
81 close_button_->SetEnabledColor(SK_ColorWHITE); 81 close_button_->SetEnabledColor(SK_ColorWHITE);
82 close_button_->SetHoverColor(SK_ColorDKGRAY); 82 close_button_->SetHoverColor(SK_ColorDKGRAY);
83 close_button_->set_alignment(views::TextButton::ALIGN_CENTER); 83 close_button_->set_alignment(views::TextButton::ALIGN_CENTER);
84 close_button_->set_icon_placement(views::TextButton::ICON_ON_RIGHT); 84 close_button_->set_icon_placement(views::TextButton::ICON_ON_RIGHT);
85 AddChildView(close_button_); 85 AddChildView(close_button_);
(...skipping 16 matching lines...) Expand all
102 source_label_->SetColor(SK_ColorWHITE); 102 source_label_->SetColor(SK_ColorWHITE);
103 source_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 103 source_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
104 AddChildView(source_label_); 104 AddChildView(source_label_);
105 } 105 }
106 notification_registrar_.Add(this, 106 notification_registrar_.Add(this,
107 NotificationType::NOTIFY_BALLOON_DISCONNECTED, Source<Balloon>(balloon)); 107 NotificationType::NOTIFY_BALLOON_DISCONNECTED, Source<Balloon>(balloon));
108 } 108 }
109 109
110 void BalloonViewImpl::Update() { 110 void BalloonViewImpl::Update() {
111 stale_ = false; 111 stale_ = false;
112 html_contents_->render_view_host()->NavigateToURL( 112 if (html_contents_->render_view_host())
113 balloon_->notification().content_url()); 113 html_contents_->render_view_host()->NavigateToURL(
114 balloon_->notification().content_url());
114 } 115 }
115 116
116 void BalloonViewImpl::Close(bool by_user) { 117 void BalloonViewImpl::Close(bool by_user) {
117 MessageLoop::current()->PostTask( 118 MessageLoop::current()->PostTask(
118 FROM_HERE, 119 FROM_HERE,
119 method_factory_.NewRunnableMethod( 120 method_factory_.NewRunnableMethod(
120 &BalloonViewImpl::DelayedClose, by_user)); 121 &BalloonViewImpl::DelayedClose, by_user));
121 } 122 }
122 123
123 gfx::Size BalloonViewImpl::GetSize() const { 124 gfx::Size BalloonViewImpl::GetSize() const {
(...skipping 14 matching lines...) Expand all
138 button_size = close_button_->GetPreferredSize(); 139 button_size = close_button_->GetPreferredSize();
139 } 140 }
140 141
141 SetBounds(x(), y(), 142 SetBounds(x(), y(),
142 balloon_->content_size().width(), 143 balloon_->content_size().width(),
143 balloon_->content_size().height() + 144 balloon_->content_size().height() +
144 button_size.height()); 145 button_size.height());
145 int x = width() - button_size.width(); 146 int x = width() - button_size.width();
146 int y = height() - button_size.height(); 147 int y = height() - button_size.height();
147 148
148 html_contents_->SetBounds(0, 0, width(), y); 149 html_contents_->view()->SetBounds(0, 0, width(), y);
149 if (html_contents_->render_view_host()) { 150 if (html_contents_->render_view_host()) {
150 RenderWidgetHostView* view = html_contents_->render_view_host()->view(); 151 RenderWidgetHostView* view = html_contents_->render_view_host()->view();
151 if (view) 152 if (view)
152 view->SetSize(gfx::Size(width(), y)); 153 view->SetSize(gfx::Size(width(), y));
153 } 154 }
154 if (controls_) { 155 if (controls_) {
155 close_button_->SetBounds(x, y, button_size.width(), button_size.height()); 156 close_button_->SetBounds(x, y, button_size.width(), button_size.height());
156 x -= close_button_->GetPreferredSize().width(); 157 x -= close_button_->GetPreferredSize().width();
157 options_menu_button_->SetBounds( 158 options_menu_button_->SetBounds(
158 x, y, button_size.width(), button_size.height()); 159 x, y, button_size.width(), button_size.height());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get())); 243 options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get()));
243 } 244 }
244 245
245 void BalloonViewImpl::DelayedClose(bool by_user) { 246 void BalloonViewImpl::DelayedClose(bool by_user) {
246 html_contents_->Shutdown(); 247 html_contents_->Shutdown();
247 html_contents_ = NULL; 248 html_contents_ = NULL;
248 balloon_->OnClose(by_user); 249 balloon_->OnClose(by_user);
249 } 250 }
250 251
251 } // namespace chromeos 252 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/notifications/balloon_view_host_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698