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

Side by Side Diff: chrome/browser/ui/views/infobars/link_infobar.cc

Issue 11721003: Eliminate the LinkInfoBar[Delegate] classes entirely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address some nits - testing-automation matters? Created 7 years, 11 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 | « chrome/browser/ui/views/infobars/link_infobar.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/infobars/link_infobar.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/api/infobars/link_infobar_delegate.h"
9 #include "chrome/browser/event_disposition.h"
10 #include "ui/views/controls/label.h"
11 #include "ui/views/controls/link.h"
12
13 // LinkInfoBarDelegate --------------------------------------------------------
14
15 InfoBar* LinkInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
16 return new LinkInfoBar(owner, this);
17 }
18
19 // LinkInfoBar ----------------------------------------------------------------
20
21 LinkInfoBar::LinkInfoBar(InfoBarService* owner,
22 LinkInfoBarDelegate* delegate)
23 : InfoBarView(owner, delegate),
24 label_1_(NULL),
25 link_(NULL),
26 label_2_(NULL) {
27 }
28
29 LinkInfoBar::~LinkInfoBar() {
30 }
31
32 void LinkInfoBar::Layout() {
33 InfoBarView::Layout();
34
35 // TODO(pkasting): This isn't perfect; there are points when we should elide a
36 // view because its subsequent view will be too small to show an ellipsis.
37 gfx::Size label_1_size = label_1_->GetPreferredSize();
38 int available_width = EndX() - StartX();
39 label_1_->SetBounds(StartX(), OffsetY(label_1_size),
40 std::min(label_1_size.width(), available_width), label_1_size.height());
41 available_width = std::max(0, available_width - label_1_size.width());
42
43 gfx::Size link_size = link_->GetPreferredSize();
44 link_->SetBounds(label_1_->bounds().right(), OffsetY(link_size),
45 std::min(link_size.width(), available_width), link_size.height());
46 available_width = std::max(0, available_width - link_size.width());
47
48 gfx::Size label_2_size = label_2_->GetPreferredSize();
49 label_2_->SetBounds(link_->bounds().right(), OffsetY(label_2_size),
50 std::min(label_2_size.width(), available_width), label_2_size.height());
51 }
52
53 void LinkInfoBar::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
54 if (is_add && (child == this) && (label_1_ == NULL)) {
55 LinkInfoBarDelegate* delegate = GetDelegate();
56 size_t offset;
57 string16 message_text = delegate->GetMessageTextWithOffset(&offset);
58 DCHECK_NE(string16::npos, offset);
59 label_1_ = CreateLabel(message_text.substr(0, offset));
60 AddChildView(label_1_);
61
62 link_ = CreateLink(delegate->GetLinkText(), this);
63 AddChildView(link_);
64
65 label_2_ = CreateLabel(message_text.substr(offset));
66 AddChildView(label_2_);
67 }
68
69 // This must happen after adding all other children so InfoBarView can ensure
70 // the close button is the last child.
71 InfoBarView::ViewHierarchyChanged(is_add, parent, child);
72 }
73
74 void LinkInfoBar::LinkClicked(views::Link* source, int event_flags) {
75 if (!owned())
76 return; // We're closing; don't call anything, it might access the owner.
77 DCHECK(link_ != NULL);
78 DCHECK_EQ(link_, source);
79 if (GetDelegate()->LinkClicked(
80 chrome::DispositionFromEventFlags(event_flags)))
81 RemoveSelf();
82 }
83
84 LinkInfoBarDelegate* LinkInfoBar::GetDelegate() {
85 return delegate()->AsLinkInfoBarDelegate();
86 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/link_infobar.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698