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

Side by Side Diff: chrome/browser/ui/views/infobars/alternate_nav_infobar_view.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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/ui/views/infobars/link_infobar.h" 5 #include "chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/api/infobars/link_infobar_delegate.h"
9 #include "chrome/browser/event_disposition.h" 8 #include "chrome/browser/event_disposition.h"
9 #include "chrome/browser/infobars/alternate_nav_infobar_delegate.h"
10 #include "ui/views/controls/label.h" 10 #include "ui/views/controls/label.h"
11 #include "ui/views/controls/link.h" 11 #include "ui/views/controls/link.h"
12 12
13 // LinkInfoBarDelegate -------------------------------------------------------- 13 // AlternateNavInfoBarDelegate -------------------------------------------------
14 14
15 InfoBar* LinkInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { 15 InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
16 return new LinkInfoBar(owner, this); 16 return new AlternateNavInfoBarView(owner, this);
17 } 17 }
18 18
19 // LinkInfoBar ---------------------------------------------------------------- 19 // AlternateNavInfoBarView -----------------------------------------------------
20 20
21 LinkInfoBar::LinkInfoBar(InfoBarService* owner, 21 AlternateNavInfoBarView::AlternateNavInfoBarView(
22 LinkInfoBarDelegate* delegate) 22 InfoBarService* owner,
23 AlternateNavInfoBarDelegate* delegate)
23 : InfoBarView(owner, delegate), 24 : InfoBarView(owner, delegate),
24 label_1_(NULL), 25 label_1_(NULL),
25 link_(NULL), 26 link_(NULL),
26 label_2_(NULL) { 27 label_2_(NULL) {
27 } 28 }
28 29
29 LinkInfoBar::~LinkInfoBar() { 30 AlternateNavInfoBarView::~AlternateNavInfoBarView() {
30 } 31 }
31 32
32 void LinkInfoBar::Layout() { 33 void AlternateNavInfoBarView::Layout() {
33 InfoBarView::Layout(); 34 InfoBarView::Layout();
34 35
35 // TODO(pkasting): This isn't perfect; there are points when we should elide a 36 // 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 // view because its subsequent view will be too small to show an ellipsis.
37 gfx::Size label_1_size = label_1_->GetPreferredSize(); 38 gfx::Size label_1_size = label_1_->GetPreferredSize();
38 int available_width = EndX() - StartX(); 39 int available_width = EndX() - StartX();
39 label_1_->SetBounds(StartX(), OffsetY(label_1_size), 40 label_1_->SetBounds(StartX(), OffsetY(label_1_size),
40 std::min(label_1_size.width(), available_width), label_1_size.height()); 41 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 available_width = std::max(0, available_width - label_1_size.width());
42 43
43 gfx::Size link_size = link_->GetPreferredSize(); 44 gfx::Size link_size = link_->GetPreferredSize();
44 link_->SetBounds(label_1_->bounds().right(), OffsetY(link_size), 45 link_->SetBounds(label_1_->bounds().right(), OffsetY(link_size),
45 std::min(link_size.width(), available_width), link_size.height()); 46 std::min(link_size.width(), available_width), link_size.height());
46 available_width = std::max(0, available_width - link_size.width()); 47 available_width = std::max(0, available_width - link_size.width());
47 48
48 gfx::Size label_2_size = label_2_->GetPreferredSize(); 49 gfx::Size label_2_size = label_2_->GetPreferredSize();
49 label_2_->SetBounds(link_->bounds().right(), OffsetY(label_2_size), 50 label_2_->SetBounds(link_->bounds().right(), OffsetY(label_2_size),
50 std::min(label_2_size.width(), available_width), label_2_size.height()); 51 std::min(label_2_size.width(), available_width), label_2_size.height());
51 } 52 }
52 53
53 void LinkInfoBar::ViewHierarchyChanged(bool is_add, View* parent, View* child) { 54 void AlternateNavInfoBarView::ViewHierarchyChanged(bool is_add,
55 View* parent,
56 View* child) {
54 if (is_add && (child == this) && (label_1_ == NULL)) { 57 if (is_add && (child == this) && (label_1_ == NULL)) {
55 LinkInfoBarDelegate* delegate = GetDelegate(); 58 AlternateNavInfoBarDelegate* delegate = GetDelegate();
56 size_t offset; 59 size_t offset;
57 string16 message_text = delegate->GetMessageTextWithOffset(&offset); 60 string16 message_text = delegate->GetMessageTextWithOffset(&offset);
58 DCHECK_NE(string16::npos, offset); 61 DCHECK_NE(string16::npos, offset);
59 label_1_ = CreateLabel(message_text.substr(0, offset)); 62 label_1_ = CreateLabel(message_text.substr(0, offset));
60 AddChildView(label_1_); 63 AddChildView(label_1_);
61 64
62 link_ = CreateLink(delegate->GetLinkText(), this); 65 link_ = CreateLink(delegate->GetLinkText(), this);
63 AddChildView(link_); 66 AddChildView(link_);
64 67
65 label_2_ = CreateLabel(message_text.substr(offset)); 68 label_2_ = CreateLabel(message_text.substr(offset));
66 AddChildView(label_2_); 69 AddChildView(label_2_);
67 } 70 }
68 71
69 // This must happen after adding all other children so InfoBarView can ensure 72 // This must happen after adding all other children so InfoBarView can ensure
70 // the close button is the last child. 73 // the close button is the last child.
71 InfoBarView::ViewHierarchyChanged(is_add, parent, child); 74 InfoBarView::ViewHierarchyChanged(is_add, parent, child);
72 } 75 }
73 76
74 void LinkInfoBar::LinkClicked(views::Link* source, int event_flags) { 77 void AlternateNavInfoBarView::LinkClicked(views::Link* source,
78 int event_flags) {
75 if (!owned()) 79 if (!owned())
76 return; // We're closing; don't call anything, it might access the owner. 80 return; // We're closing; don't call anything, it might access the owner.
77 DCHECK(link_ != NULL); 81 DCHECK(link_ != NULL);
78 DCHECK_EQ(link_, source); 82 DCHECK_EQ(link_, source);
79 if (GetDelegate()->LinkClicked( 83 if (GetDelegate()->LinkClicked(
80 chrome::DispositionFromEventFlags(event_flags))) 84 chrome::DispositionFromEventFlags(event_flags)))
81 RemoveSelf(); 85 RemoveSelf();
82 } 86 }
83 87
84 LinkInfoBarDelegate* LinkInfoBar::GetDelegate() { 88 AlternateNavInfoBarDelegate* AlternateNavInfoBarView::GetDelegate() {
85 return delegate()->AsLinkInfoBarDelegate(); 89 return delegate()->AsAlternateNavInfoBarDelegate();
86 } 90 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h ('k') | chrome/browser/ui/views/infobars/link_infobar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698