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

Side by Side Diff: ui/views/bubble/bubble_delegate.cc

Issue 8870003: Merge BorderContentsView into BubbleFrameView; simplify. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge. Created 9 years 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 | « ui/views/bubble/bubble_delegate.h ('k') | ui/views/bubble/bubble_delegate_unittest.cc » ('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) 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 "ui/views/bubble/bubble_delegate.h" 5 #include "ui/views/bubble/bubble_delegate.h"
6 6
7 #include "ui/base/animation/slide_animation.h" 7 #include "ui/base/animation/slide_animation.h"
8 #include "ui/gfx/color_utils.h" 8 #include "ui/gfx/color_utils.h"
9 #include "ui/views/bubble/bubble_frame_view.h" 9 #include "ui/views/bubble/bubble_frame_view.h"
10 #include "ui/views/widget/widget.h" 10 #include "ui/views/widget/widget.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 const SkColor BubbleDelegateView::kBackgroundColor = 76 const SkColor BubbleDelegateView::kBackgroundColor =
77 color_utils::GetSysSkColor(COLOR_WINDOW); 77 color_utils::GetSysSkColor(COLOR_WINDOW);
78 #else 78 #else
79 // TODO(beng): source from theme provider. 79 // TODO(beng): source from theme provider.
80 const SkColor BubbleDelegateView::kBackgroundColor = SK_ColorWHITE; 80 const SkColor BubbleDelegateView::kBackgroundColor = SK_ColorWHITE;
81 #endif 81 #endif
82 82
83 BubbleDelegateView::BubbleDelegateView() 83 BubbleDelegateView::BubbleDelegateView()
84 : close_on_esc_(true), 84 : close_on_esc_(true),
85 close_on_deactivate_(true), 85 close_on_deactivate_(true),
86 allow_bubble_offscreen_(false),
87 anchor_view_(NULL), 86 anchor_view_(NULL),
88 arrow_location_(BubbleBorder::TOP_LEFT), 87 arrow_location_(BubbleBorder::TOP_LEFT),
89 color_(kBackgroundColor), 88 color_(kBackgroundColor),
90 original_opacity_(255), 89 original_opacity_(255),
91 border_widget_(NULL), 90 border_widget_(NULL),
92 use_focusless_(false) { 91 use_focusless_(false) {
93 set_background(views::Background::CreateSolidBackground(color_)); 92 set_background(views::Background::CreateSolidBackground(color_));
94 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, 0)); 93 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, 0));
95 } 94 }
96 95
97 BubbleDelegateView::BubbleDelegateView( 96 BubbleDelegateView::BubbleDelegateView(
98 View* anchor_view, 97 View* anchor_view,
99 BubbleBorder::ArrowLocation arrow_location) 98 BubbleBorder::ArrowLocation arrow_location)
100 : close_on_esc_(true), 99 : close_on_esc_(true),
101 close_on_deactivate_(true), 100 close_on_deactivate_(true),
102 allow_bubble_offscreen_(false),
103 anchor_view_(anchor_view), 101 anchor_view_(anchor_view),
104 arrow_location_(arrow_location), 102 arrow_location_(arrow_location),
105 color_(kBackgroundColor), 103 color_(kBackgroundColor),
106 original_opacity_(255), 104 original_opacity_(255),
107 border_widget_(NULL), 105 border_widget_(NULL),
108 use_focusless_(false) { 106 use_focusless_(false) {
109 set_background(views::Background::CreateSolidBackground(color_)); 107 set_background(views::Background::CreateSolidBackground(color_));
110 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, 0)); 108 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, 0));
111 } 109 }
112 110
(...skipping 26 matching lines...) Expand all
139 137
140 BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() { 138 BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() {
141 return this; 139 return this;
142 } 140 }
143 141
144 View* BubbleDelegateView::GetContentsView() { 142 View* BubbleDelegateView::GetContentsView() {
145 return this; 143 return this;
146 } 144 }
147 145
148 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() { 146 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() {
149 return new BubbleFrameView(GetArrowLocation(), 147 return new BubbleFrameView(arrow_location(), color());
150 GetPreferredSize(),
151 color(),
152 allow_bubble_offscreen());
153 } 148 }
154 149
155 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, 150 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget,
156 bool active) { 151 bool active) {
157 if (close_on_deactivate() && widget == GetWidget() && !active) { 152 if (close_on_deactivate() && widget == GetWidget() && !active) {
158 GetWidget()->RemoveObserver(this); 153 GetWidget()->RemoveObserver(this);
159 GetWidget()->Close(); 154 GetWidget()->Close();
160 } 155 }
161 } 156 }
162 157
163 gfx::Rect BubbleDelegateView::GetAnchorRect() { 158 gfx::Rect BubbleDelegateView::GetAnchorRect() {
164 if (!anchor_view()) 159 return anchor_view() ? anchor_view()->GetScreenBounds() : gfx::Rect();
165 return gfx::Rect();
166
167 BubbleBorder::ArrowLocation location = GetArrowLocation();
168 gfx::Point anchor;
169 // By default, pick the middle of |anchor_view_|'s edge opposite the arrow.
170 if (BubbleBorder::is_arrow_on_horizontal(location)) {
171 anchor.SetPoint(anchor_view()->width() / 2,
172 BubbleBorder::is_arrow_on_top(location) ? anchor_view()->height() : 0);
173 } else if (BubbleBorder::has_arrow(location)) {
174 anchor.SetPoint(
175 BubbleBorder::is_arrow_on_left(location) ? anchor_view()->width() : 0,
176 anchor_view_->height() / 2);
177 } else {
178 anchor = anchor_view()->bounds().CenterPoint();
179 }
180 View::ConvertPointToScreen(anchor_view(), &anchor);
181 return gfx::Rect(anchor, gfx::Size());
182 }
183
184 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const {
185 return arrow_location_;
186 } 160 }
187 161
188 void BubbleDelegateView::Show() { 162 void BubbleDelegateView::Show() {
189 if (border_widget_) 163 if (border_widget_)
190 border_widget_->Show(); 164 border_widget_->Show();
191 GetWidget()->Show(); 165 GetWidget()->Show();
192 GetFocusManager()->SetFocusedView(GetInitiallyFocusedView()); 166 GetFocusManager()->SetFocusedView(GetInitiallyFocusedView());
193 if (anchor_view() && anchor_view()->GetWidget() && 167 if (anchor_view() && anchor_view()->GetWidget() &&
194 anchor_view()->GetWidget()->GetTopLevelWidget()) 168 anchor_view()->GetWidget()->GetTopLevelWidget())
195 anchor_view()->GetWidget()->GetTopLevelWidget()->DisableInactiveRendering(); 169 anchor_view()->GetWidget()->GetTopLevelWidget()->DisableInactiveRendering();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 253
280 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { 254 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const {
281 const Widget* widget = border_widget_ ? border_widget_ : GetWidget(); 255 const Widget* widget = border_widget_ ? border_widget_ : GetWidget();
282 const NonClientView* view = widget ? widget->non_client_view() : NULL; 256 const NonClientView* view = widget ? widget->non_client_view() : NULL;
283 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL; 257 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL;
284 } 258 }
285 259
286 gfx::Rect BubbleDelegateView::GetBubbleBounds() { 260 gfx::Rect BubbleDelegateView::GetBubbleBounds() {
287 // The argument rect has its origin at the bubble's arrow anchor point; 261 // The argument rect has its origin at the bubble's arrow anchor point;
288 // its size is the preferred size of the bubble's client view (this view). 262 // its size is the preferred size of the bubble's client view (this view).
289 return GetBubbleFrameView()->GetWindowBoundsForAnchorAndClientSize( 263 return GetBubbleFrameView()->GetUpdatedWindowBounds(GetAnchorRect(),
290 GetAnchorRect(), GetPreferredSize()); 264 GetPreferredSize(), true /*try_mirroring_arrow*/);
291 } 265 }
292 266
293 #if defined(OS_WIN) && !defined(USE_AURA) 267 #if defined(OS_WIN) && !defined(USE_AURA)
294 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { 268 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const {
295 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); 269 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView());
296 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); 270 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin());
297 return client_bounds; 271 return client_bounds;
298 } 272 }
299 #endif 273 #endif
300 274
301 } // namespace views 275 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_delegate.h ('k') | ui/views/bubble/bubble_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698