OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/link_infobar.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/tab_contents/link_infobar_delegate.h" | 8 #include "chrome/browser/tab_contents/link_infobar_delegate.h" |
9 #include "chrome/browser/ui/views/event_utils.h" | 9 #include "chrome/browser/ui/views/event_utils.h" |
10 #include "views/controls/label.h" | 10 #include "views/controls/label.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 void LinkInfoBar::ViewHierarchyChanged(bool is_add, View* parent, View* child) { | 53 void LinkInfoBar::ViewHierarchyChanged(bool is_add, View* parent, View* child) { |
54 if (is_add && (child == this) && (label_1_ == NULL)) { | 54 if (is_add && (child == this) && (label_1_ == NULL)) { |
55 LinkInfoBarDelegate* delegate = GetDelegate(); | 55 LinkInfoBarDelegate* delegate = GetDelegate(); |
56 size_t offset; | 56 size_t offset; |
57 string16 message_text = delegate->GetMessageTextWithOffset(&offset); | 57 string16 message_text = delegate->GetMessageTextWithOffset(&offset); |
58 DCHECK_NE(string16::npos, offset); | 58 DCHECK_NE(string16::npos, offset); |
59 label_1_ = CreateLabel(message_text.substr(0, offset)); | 59 label_1_ = CreateLabel(message_text.substr(0, offset)); |
60 AddChildView(label_1_); | 60 AddChildView(label_1_); |
61 | 61 |
62 link_ = CreateLink(delegate->GetLinkText(), this, | 62 link_ = CreateLink(delegate->GetLinkText(), this); |
63 background()->get_color()); | |
64 AddChildView(link_); | 63 AddChildView(link_); |
65 | 64 |
66 label_2_ = CreateLabel(message_text.substr(offset)); | 65 label_2_ = CreateLabel(message_text.substr(offset)); |
67 AddChildView(label_2_); | 66 AddChildView(label_2_); |
68 } | 67 } |
69 | 68 |
70 // This must happen after adding all other children so InfoBarView can ensure | 69 // This must happen after adding all other children so InfoBarView can ensure |
71 // the close button is the last child. | 70 // the close button is the last child. |
72 InfoBarView::ViewHierarchyChanged(is_add, parent, child); | 71 InfoBarView::ViewHierarchyChanged(is_add, parent, child); |
73 } | 72 } |
74 | 73 |
75 void LinkInfoBar::LinkClicked(views::Link* source, int event_flags) { | 74 void LinkInfoBar::LinkClicked(views::Link* source, int event_flags) { |
76 if (!owned()) | 75 if (!owned()) |
77 return; // We're closing; don't call anything, it might access the owner. | 76 return; // We're closing; don't call anything, it might access the owner. |
78 DCHECK(link_ != NULL); | 77 DCHECK(link_ != NULL); |
79 DCHECK_EQ(link_, source); | 78 DCHECK_EQ(link_, source); |
80 if (GetDelegate()->LinkClicked( | 79 if (GetDelegate()->LinkClicked( |
81 event_utils::DispositionFromEventFlags(event_flags))) | 80 event_utils::DispositionFromEventFlags(event_flags))) |
82 RemoveSelf(); | 81 RemoveSelf(); |
83 } | 82 } |
84 | 83 |
85 LinkInfoBarDelegate* LinkInfoBar::GetDelegate() { | 84 LinkInfoBarDelegate* LinkInfoBar::GetDelegate() { |
86 return delegate()->AsLinkInfoBarDelegate(); | 85 return delegate()->AsLinkInfoBarDelegate(); |
87 } | 86 } |
OLD | NEW |