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. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 event.flags()); | 144 event.flags()); |
146 } | 145 } |
147 Close(); | 146 Close(); |
148 } | 147 } |
149 | 148 |
150 gfx::Rect AppListView::GetBubbleBounds() { | 149 gfx::Rect AppListView::GetBubbleBounds() { |
151 // This happens before replacing the default border. | 150 // This happens before replacing the default border. |
152 if (!bubble_border_) | 151 if (!bubble_border_) |
153 return views::BubbleDelegateView::GetBubbleBounds(); | 152 return views::BubbleDelegateView::GetBubbleBounds(); |
154 | 153 |
155 const gfx::Point old_offset = bubble_border_->offset(); | |
156 const gfx::Rect anchor_rect = GetAnchorRect(); | 154 const gfx::Rect anchor_rect = GetAnchorRect(); |
157 | |
158 bubble_border_->set_offset(gfx::Point()); | |
159 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( | 155 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds( |
160 anchor_rect, | 156 anchor_rect, |
161 GetPreferredSize(), | 157 GetPreferredSize(), |
162 false /* try_mirroring_arrow */); | 158 false /* try_mirroring_arrow */); |
163 | 159 |
164 gfx::Rect monitor_rect = gfx::Screen::GetDisplayNearestPoint( | 160 const gfx::Point old_offset = bubble_border_->offset(); |
165 anchor_rect.CenterPoint()).work_area(); | 161 bubble_rect = bubble_border_->ComputeOffsetAndUpdateBubbleRect(bubble_rect, |
166 if (monitor_rect.IsEmpty() || monitor_rect.Contains(bubble_rect)) | 162 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 | 163 |
186 // Repaints border if arrow offset is changed. | 164 // Repaints border if arrow offset is changed. |
187 if (bubble_border_->offset() != old_offset) | 165 if (bubble_border_->offset() != old_offset) |
188 GetBubbleFrameView()->SchedulePaint(); | 166 GetBubbleFrameView()->SchedulePaint(); |
189 | 167 |
190 return bubble_rect; | 168 return bubble_rect; |
191 } | 169 } |
192 | 170 |
193 void AppListView::QueryChanged(SearchBoxView* sender) { | 171 void AppListView::QueryChanged(SearchBoxView* sender) { |
194 bool should_show_search = !model_->search_box()->text().empty(); | 172 bool should_show_search = !model_->search_box()->text().empty(); |
195 contents_view_->ShowSearchResults(should_show_search); | 173 contents_view_->ShowSearchResults(should_show_search); |
196 | 174 |
197 if (delegate_.get()) { | 175 if (delegate_.get()) { |
198 if (should_show_search) | 176 if (should_show_search) |
199 delegate_->StartSearch(); | 177 delegate_->StartSearch(); |
200 else | 178 else |
201 delegate_->StopSearch(); | 179 delegate_->StopSearch(); |
202 } | 180 } |
203 } | 181 } |
204 | 182 |
205 void AppListView::OpenResult(const SearchResult& result, int event_flags) { | 183 void AppListView::OpenResult(const SearchResult& result, int event_flags) { |
206 if (delegate_.get()) | 184 if (delegate_.get()) |
207 delegate_->OpenSearchResult(result, event_flags); | 185 delegate_->OpenSearchResult(result, event_flags); |
208 Close(); | 186 Close(); |
209 } | 187 } |
210 | 188 |
211 } // namespace app_list | 189 } // namespace app_list |
OLD | NEW |