OLD | NEW |
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/alternate_nav_infobar_view.h" | 5 #include "chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 void AlternateNavInfoBarView::ViewHierarchyChanged( | 75 void AlternateNavInfoBarView::ViewHierarchyChanged( |
76 const ViewHierarchyChangedDetails& details) { | 76 const ViewHierarchyChangedDetails& details) { |
77 if (details.is_add && (details.child == this) && (label_1_ == NULL)) { | 77 if (details.is_add && (details.child == this) && (label_1_ == NULL)) { |
78 AlternateNavInfoBarDelegate* delegate = GetDelegate(); | 78 AlternateNavInfoBarDelegate* delegate = GetDelegate(); |
79 size_t offset; | 79 size_t offset; |
80 base::string16 message_text = delegate->GetMessageTextWithOffset(&offset); | 80 base::string16 message_text = delegate->GetMessageTextWithOffset(&offset); |
81 DCHECK_NE(base::string16::npos, offset); | 81 DCHECK_NE(base::string16::npos, offset); |
82 label_1_text_ = message_text.substr(0, offset); | 82 label_1_text_ = message_text.substr(0, offset); |
83 label_1_ = CreateLabel(label_1_text_); | 83 label_1_ = CreateLabel(label_1_text_); |
84 AddChildView(label_1_); | 84 AddViewToContentArea(label_1_); |
85 | 85 |
86 link_text_ = delegate->GetLinkText(); | 86 link_text_ = delegate->GetLinkText(); |
87 link_ = CreateLink(link_text_, this); | 87 link_ = CreateLink(link_text_, this); |
88 AddChildView(link_); | 88 AddViewToContentArea(link_); |
89 | 89 |
90 label_2_text_ = message_text.substr(offset); | 90 label_2_text_ = message_text.substr(offset); |
91 label_2_ = CreateLabel(label_2_text_); | 91 label_2_ = CreateLabel(label_2_text_); |
92 AddChildView(label_2_); | 92 AddViewToContentArea(label_2_); |
93 } | 93 } |
94 | 94 |
95 // This must happen after adding all other children so InfoBarView can ensure | 95 // This must happen after adding all other children so InfoBarView can ensure |
96 // the close button is the last child. | 96 // the close button is the last child. |
97 InfoBarView::ViewHierarchyChanged(details); | 97 InfoBarView::ViewHierarchyChanged(details); |
98 } | 98 } |
99 | 99 |
100 int AlternateNavInfoBarView::ContentMinimumWidth() const { | 100 int AlternateNavInfoBarView::ContentMinimumWidth() const { |
101 int label_1_width = label_1_->GetMinimumSize().width(); | 101 int label_1_width = label_1_->GetMinimumSize().width(); |
102 return label_1_width ? label_1_width : link_->GetMinimumSize().width(); | 102 return label_1_width ? label_1_width : link_->GetMinimumSize().width(); |
103 } | 103 } |
104 | 104 |
105 void AlternateNavInfoBarView::LinkClicked(views::Link* source, | 105 void AlternateNavInfoBarView::LinkClicked(views::Link* source, |
106 int event_flags) { | 106 int event_flags) { |
107 if (!owner()) | 107 if (!owner()) |
108 return; // We're closing; don't call anything, it might access the owner. | 108 return; // We're closing; don't call anything, it might access the owner. |
109 DCHECK(link_ != NULL); | 109 DCHECK(link_ != NULL); |
110 DCHECK_EQ(link_, source); | 110 DCHECK_EQ(link_, source); |
111 if (GetDelegate()->LinkClicked(ui::DispositionFromEventFlags(event_flags))) | 111 if (GetDelegate()->LinkClicked(ui::DispositionFromEventFlags(event_flags))) |
112 RemoveSelf(); | 112 RemoveSelf(); |
113 } | 113 } |
114 | 114 |
115 AlternateNavInfoBarDelegate* AlternateNavInfoBarView::GetDelegate() { | 115 AlternateNavInfoBarDelegate* AlternateNavInfoBarView::GetDelegate() { |
116 return static_cast<AlternateNavInfoBarDelegate*>(delegate()); | 116 return static_cast<AlternateNavInfoBarDelegate*>(delegate()); |
117 } | 117 } |
OLD | NEW |