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 "ui/app_list/app_list_view.h" | 5 #include "ui/app_list/app_list_view.h" |
6 | 6 |
7 #include "ui/app_list/app_list_bubble_border.h" | 7 #include "ui/app_list/app_list_bubble_border.h" |
8 #include "ui/app_list/app_list_item_view.h" | 8 #include "ui/app_list/app_list_item_view.h" |
9 #include "ui/app_list/app_list_model.h" | 9 #include "ui/app_list/app_list_model.h" |
10 #include "ui/app_list/app_list_view_delegate.h" | 10 #include "ui/app_list/app_list_view_delegate.h" |
11 #include "ui/app_list/contents_view.h" | 11 #include "ui/app_list/contents_view.h" |
12 #include "ui/app_list/pagination_model.h" | 12 #include "ui/app_list/pagination_model.h" |
13 #include "ui/app_list/search_box_model.h" | 13 #include "ui/app_list/search_box_model.h" |
14 #include "ui/app_list/search_box_view.h" | 14 #include "ui/app_list/search_box_view.h" |
15 #include "ui/gfx/insets.h" | 15 #include "ui/gfx/insets.h" |
16 #include "ui/gfx/screen.h" | |
17 #include "ui/views/bubble/bubble_frame_view.h" | 16 #include "ui/views/bubble/bubble_frame_view.h" |
18 #include "ui/views/controls/textfield/textfield.h" | 17 #include "ui/views/controls/textfield/textfield.h" |
19 #include "ui/views/layout/box_layout.h" | 18 #include "ui/views/layout/box_layout.h" |
20 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
21 | 20 |
22 namespace app_list { | 21 namespace app_list { |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 // Inner padding space in pixels of bubble contents. | 25 // Inner padding space in pixels of bubble contents. |
27 const int kInnerPadding = 1; | 26 const int kInnerPadding = 1; |
28 | 27 |
| 28 // The distance between the arrow tip and edge of the anchor view. |
| 29 const int kArrowOffset = 10; |
| 30 |
29 } // namespace | 31 } // namespace |
30 | 32 |
31 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
32 // AppListView: | 34 // AppListView: |
33 | 35 |
34 AppListView::AppListView(AppListViewDelegate* delegate) | 36 AppListView::AppListView(AppListViewDelegate* delegate) |
35 : delegate_(delegate), | 37 : delegate_(delegate), |
36 bubble_border_(NULL), | 38 bubble_border_(NULL), |
37 search_box_view_(NULL), | 39 search_box_view_(NULL), |
38 contents_view_(NULL) { | 40 contents_view_(NULL) { |
(...skipping 22 matching lines...) Expand all Loading... |
61 contents_view_ = new ContentsView(this, pagination_model); | 63 contents_view_ = new ContentsView(this, pagination_model); |
62 AddChildView(contents_view_); | 64 AddChildView(contents_view_); |
63 | 65 |
64 search_box_view_->set_contents_view(contents_view_); | 66 search_box_view_->set_contents_view(contents_view_); |
65 | 67 |
66 set_anchor_view(anchor); | 68 set_anchor_view(anchor); |
67 set_margins(gfx::Insets()); | 69 set_margins(gfx::Insets()); |
68 set_move_with_anchor(true); | 70 set_move_with_anchor(true); |
69 set_parent_window(parent); | 71 set_parent_window(parent); |
70 set_close_on_deactivate(false); | 72 set_close_on_deactivate(false); |
| 73 set_anchor_insets(gfx::Insets(kArrowOffset, kArrowOffset, kArrowOffset, |
| 74 kArrowOffset)); |
71 views::BubbleDelegateView::CreateBubble(this); | 75 views::BubbleDelegateView::CreateBubble(this); |
72 | 76 |
73 // Resets default background since AppListBubbleBorder paints background. | 77 // Resets default background since AppListBubbleBorder paints background. |
74 GetBubbleFrameView()->set_background(NULL); | 78 GetBubbleFrameView()->set_background(NULL); |
75 | 79 |
76 // Overrides border with AppListBubbleBorder. | 80 // Overrides border with AppListBubbleBorder. |
77 bubble_border_ = new AppListBubbleBorder(this, search_box_view_); | 81 bubble_border_ = new AppListBubbleBorder(this, search_box_view_); |
78 GetBubbleFrameView()->SetBubbleBorder(bubble_border_); | 82 GetBubbleFrameView()->SetBubbleBorder(bubble_border_); |
79 SetBubbleArrowLocation(arrow_location); | 83 SetBubbleArrowLocation(arrow_location); |
80 | 84 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 event.flags()); | 149 event.flags()); |
146 } | 150 } |
147 Close(); | 151 Close(); |
148 } | 152 } |
149 | 153 |
150 gfx::Rect AppListView::GetBubbleBounds() { | 154 gfx::Rect AppListView::GetBubbleBounds() { |
151 // This happens before replacing the default border. | 155 // This happens before replacing the default border. |
152 if (!bubble_border_) | 156 if (!bubble_border_) |
153 return views::BubbleDelegateView::GetBubbleBounds(); | 157 return views::BubbleDelegateView::GetBubbleBounds(); |
154 | 158 |
155 const gfx::Point old_offset = bubble_border_->offset(); | |
156 const gfx::Rect anchor_rect = GetAnchorRect(); | 159 const gfx::Rect anchor_rect = GetAnchorRect(); |
157 | |
158 bubble_border_->set_offset(gfx::Point()); | |
159 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( | 160 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( |
160 anchor_rect, | 161 anchor_rect, |
161 GetPreferredSize(), | 162 GetPreferredSize(), |
162 false /* try_mirroring_arrow */); | 163 false /* try_mirroring_arrow */); |
163 | 164 |
164 gfx::Rect monitor_rect = gfx::Screen::GetDisplayNearestPoint( | 165 const gfx::Point old_offset = bubble_border_->offset(); |
165 anchor_rect.CenterPoint()).work_area(); | 166 bubble_rect = bubble_border_->ComputeOffsetAndUpdateBubbleRect(bubble_rect, |
166 if (monitor_rect.IsEmpty() || monitor_rect.Contains(bubble_rect)) | 167 anchor_rect); |
167 return bubble_rect; | |
168 | |
169 gfx::Point offset; | |
170 | |
171 if (bubble_border_->ArrowAtTopOrBottom()) { | |
172 if (bubble_rect.x() < monitor_rect.x()) | |
173 offset.set_x(monitor_rect.x() - bubble_rect.x()); | |
174 else if (bubble_rect.right() > monitor_rect.right()) | |
175 offset.set_x(monitor_rect.right() - bubble_rect.right()); | |
176 } else if (bubble_border_->ArrowOnLeftOrRight()) { | |
177 if (bubble_rect.y() < monitor_rect.y()) | |
178 offset.set_y(monitor_rect.y() - bubble_rect.y()); | |
179 else if (bubble_rect.bottom() > monitor_rect.bottom()) | |
180 offset.set_y(monitor_rect.bottom() - bubble_rect.bottom()); | |
181 } | |
182 | |
183 bubble_rect.Offset(offset); | |
184 bubble_border_->set_offset(offset); | |
185 | 168 |
186 // Repaints border if arrow offset is changed. | 169 // Repaints border if arrow offset is changed. |
187 if (bubble_border_->offset() != old_offset) | 170 if (bubble_border_->offset() != old_offset) |
188 GetBubbleFrameView()->SchedulePaint(); | 171 GetBubbleFrameView()->SchedulePaint(); |
189 | 172 |
190 return bubble_rect; | 173 return bubble_rect; |
191 } | 174 } |
192 | 175 |
193 void AppListView::QueryChanged(SearchBoxView* sender) { | 176 void AppListView::QueryChanged(SearchBoxView* sender) { |
194 bool should_show_search = !model_->search_box()->text().empty(); | 177 bool should_show_search = !model_->search_box()->text().empty(); |
195 contents_view_->ShowSearchResults(should_show_search); | 178 contents_view_->ShowSearchResults(should_show_search); |
196 | 179 |
197 if (delegate_.get()) { | 180 if (delegate_.get()) { |
198 if (should_show_search) | 181 if (should_show_search) |
199 delegate_->StartSearch(); | 182 delegate_->StartSearch(); |
200 else | 183 else |
201 delegate_->StopSearch(); | 184 delegate_->StopSearch(); |
202 } | 185 } |
203 } | 186 } |
204 | 187 |
205 void AppListView::OpenResult(const SearchResult& result, int event_flags) { | 188 void AppListView::OpenResult(const SearchResult& result, int event_flags) { |
206 if (delegate_.get()) | 189 if (delegate_.get()) |
207 delegate_->OpenSearchResult(result, event_flags); | 190 delegate_->OpenSearchResult(result, event_flags); |
208 Close(); | 191 Close(); |
209 } | 192 } |
210 | 193 |
211 } // namespace app_list | 194 } // namespace app_list |
OLD | NEW |