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

Side by Side Diff: ui/app_list/app_list_view.cc

Issue 10905311: Consolidate bubble border code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove USE_AURA ifdef for kBigShadowImages and kSmalleShadowImages Created 8 years, 3 months 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
OLDNEW
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 "base/string_util.h" 7 #include "base/string_util.h"
8 #include "ui/app_list/app_list_bubble_border.h" 8 #include "ui/app_list/app_list_background.h"
9 #include "ui/app_list/app_list_constants.h" 9 #include "ui/app_list/app_list_constants.h"
10 #include "ui/app_list/app_list_item_view.h" 10 #include "ui/app_list/app_list_item_view.h"
11 #include "ui/app_list/app_list_model.h" 11 #include "ui/app_list/app_list_model.h"
12 #include "ui/app_list/app_list_view_delegate.h" 12 #include "ui/app_list/app_list_view_delegate.h"
13 #include "ui/app_list/contents_view.h" 13 #include "ui/app_list/contents_view.h"
14 #include "ui/app_list/pagination_model.h" 14 #include "ui/app_list/pagination_model.h"
15 #include "ui/app_list/search_box_model.h" 15 #include "ui/app_list/search_box_model.h"
16 #include "ui/app_list/search_box_view.h" 16 #include "ui/app_list/search_box_view.h"
17 #include "ui/base/events/event.h" 17 #include "ui/base/events/event.h"
18 #include "ui/gfx/insets.h" 18 #include "ui/gfx/insets.h"
19 #include "ui/gfx/path.h"
20 #include "ui/gfx/skia_util.h"
19 #include "ui/views/bubble/bubble_frame_view.h" 21 #include "ui/views/bubble/bubble_frame_view.h"
20 #include "ui/views/controls/textfield/textfield.h" 22 #include "ui/views/controls/textfield/textfield.h"
21 #include "ui/views/layout/box_layout.h" 23 #include "ui/views/layout/box_layout.h"
22 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
23 25
24 namespace app_list { 26 namespace app_list {
25 27
26 namespace { 28 namespace {
27 29
28 // Inner padding space in pixels of bubble contents. 30 // Inner padding space in pixels of bubble contents.
29 const int kInnerPadding = 1; 31 const int kInnerPadding = 1;
30 32
31 // The distance between the arrow tip and edge of the anchor view. 33 // The distance between the arrow tip and edge of the anchor view.
32 const int kArrowOffset = 10; 34 const int kArrowOffset = 10;
33 35
34 } // namespace 36 } // namespace
35 37
36 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
37 // AppListView: 39 // AppListView:
38 40
39 AppListView::AppListView(AppListViewDelegate* delegate) 41 AppListView::AppListView(AppListViewDelegate* delegate)
40 : delegate_(delegate), 42 : delegate_(delegate),
41 bubble_border_(NULL),
42 search_box_view_(NULL), 43 search_box_view_(NULL),
43 contents_view_(NULL) { 44 contents_view_(NULL) {
44 } 45 }
45 46
46 AppListView::~AppListView() { 47 AppListView::~AppListView() {
47 // Deletes all child views while the models are still valid. 48 // Deletes all child views while the models are still valid.
48 RemoveAllChildViews(true); 49 RemoveAllChildViews(true);
49 } 50 }
50 51
51 void AppListView::InitAsBubble( 52 void AppListView::InitAsBubble(
(...skipping 17 matching lines...) Expand all
69 search_box_view_ = new SearchBoxView(this); 70 search_box_view_ = new SearchBoxView(this);
70 AddChildView(search_box_view_); 71 AddChildView(search_box_view_);
71 72
72 contents_view_ = new ContentsView(this, pagination_model); 73 contents_view_ = new ContentsView(this, pagination_model);
73 AddChildView(contents_view_); 74 AddChildView(contents_view_);
74 75
75 search_box_view_->set_contents_view(contents_view_); 76 search_box_view_->set_contents_view(contents_view_);
76 77
77 set_anchor_view(anchor); 78 set_anchor_view(anchor);
78 set_anchor_point(anchor_point); 79 set_anchor_point(anchor_point);
80 set_color(kContentsBackgroundColor);
79 set_margins(gfx::Insets()); 81 set_margins(gfx::Insets());
80 set_move_with_anchor(true); 82 set_move_with_anchor(true);
81 set_parent_window(parent); 83 set_parent_window(parent);
82 set_close_on_deactivate(false); 84 set_close_on_deactivate(false);
83 set_anchor_insets(gfx::Insets(kArrowOffset, kArrowOffset, kArrowOffset, 85 // Shift anchor rect up 1px because app menu icon center is 1px above anchor
84 kArrowOffset)); 86 // rect center when shelf is on left/right.
87 set_anchor_insets(gfx::Insets(kArrowOffset - 1, kArrowOffset,
88 kArrowOffset + 1, kArrowOffset));
89 set_shadow(views::BubbleBorder::BIG_SHADOW);
85 views::BubbleDelegateView::CreateBubble(this); 90 views::BubbleDelegateView::CreateBubble(this);
86
87 // Overrides border with AppListBubbleBorder.
88 bubble_border_ = new AppListBubbleBorder(this, search_box_view_);
89 GetBubbleFrameView()->SetBubbleBorder(bubble_border_);
90 SetBubbleArrowLocation(arrow_location); 91 SetBubbleArrowLocation(arrow_location);
91 92
92 #if !defined(OS_WIN) 93 #if !defined(OS_WIN)
93 // Resets default background since AppListBubbleBorder paints background. 94 GetBubbleFrameView()->set_background(new AppListBackground(
94 GetBubbleFrameView()->set_background(NULL); 95 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(),
96 search_box_view_));
95 97
96 contents_view_->SetPaintToLayer(true); 98 contents_view_->SetPaintToLayer(true);
97 contents_view_->SetFillsBoundsOpaquely(false); 99 contents_view_->SetFillsBoundsOpaquely(false);
98 contents_view_->layer()->SetMasksToBounds(true); 100 contents_view_->layer()->SetMasksToBounds(true);
99 #endif 101 #endif
100 102
101 CreateModel(); 103 CreateModel();
102 } 104 }
103 105
104 void AppListView::SetBubbleArrowLocation( 106 void AppListView::SetBubbleArrowLocation(
105 views::BubbleBorder::ArrowLocation arrow_location) { 107 views::BubbleBorder::ArrowLocation arrow_location) {
106 DCHECK(bubble_border_); 108 GetBubbleFrameView()->bubble_border()->set_arrow_location(arrow_location);
107 bubble_border_->set_arrow_location(arrow_location);
108 SizeToContents(); // Recalcuates with new border. 109 SizeToContents(); // Recalcuates with new border.
110 GetBubbleFrameView()->SchedulePaint();
109 } 111 }
110 112
111 void AppListView::Close() { 113 void AppListView::Close() {
112 if (delegate_.get()) 114 if (delegate_.get())
113 delegate_->Close(); 115 delegate_->Close();
114 else 116 else
115 GetWidget()->Close(); 117 GetWidget()->Close();
116 } 118 }
117 119
118 void AppListView::UpdateBounds() { 120 void AppListView::UpdateBounds() {
(...skipping 23 matching lines...) Expand all
142 144
143 return gfx::ImageSkia(); 145 return gfx::ImageSkia();
144 } 146 }
145 147
146 bool AppListView::HasHitTestMask() const { 148 bool AppListView::HasHitTestMask() const {
147 return true; 149 return true;
148 } 150 }
149 151
150 void AppListView::GetHitTestMask(gfx::Path* mask) const { 152 void AppListView::GetHitTestMask(gfx::Path* mask) const {
151 DCHECK(mask); 153 DCHECK(mask);
152 bubble_border_->GetMask(GetBubbleFrameView()->bounds(), mask); 154 mask->addRect(gfx::RectToSkRect(
155 GetBubbleFrameView()->GetContentsBounds()));
153 } 156 }
154 157
155 bool AppListView::OnKeyPressed(const ui::KeyEvent& event) { 158 bool AppListView::OnKeyPressed(const ui::KeyEvent& event) {
156 if (event.key_code() == ui::VKEY_ESCAPE) { 159 if (event.key_code() == ui::VKEY_ESCAPE) {
157 Close(); 160 Close();
158 return true; 161 return true;
159 } 162 }
160 163
161 return false; 164 return false;
162 } 165 }
163 166
164 void AppListView::ButtonPressed(views::Button* sender, const ui::Event& event) { 167 void AppListView::ButtonPressed(views::Button* sender, const ui::Event& event) {
165 if (sender->GetClassName() != AppListItemView::kViewClassName) 168 if (sender->GetClassName() != AppListItemView::kViewClassName)
166 return; 169 return;
167 170
168 if (delegate_.get()) { 171 if (delegate_.get()) {
169 delegate_->ActivateAppListItem( 172 delegate_->ActivateAppListItem(
170 static_cast<AppListItemView*>(sender)->model(), 173 static_cast<AppListItemView*>(sender)->model(),
171 event.flags()); 174 event.flags());
172 } 175 }
173 Close(); 176 Close();
174 } 177 }
175 178
176 gfx::Rect AppListView::GetBubbleBounds() {
177 // This happens before replacing the default border.
178 if (!bubble_border_)
179 return views::BubbleDelegateView::GetBubbleBounds();
180
181 const gfx::Rect anchor_rect = GetAnchorRect();
182 gfx::Rect bubble_rect = GetBubbleFrameView()->GetUpdatedWindowBounds(
183 anchor_rect,
184 GetPreferredSize(),
185 false /* try_mirroring_arrow */);
186
187 const gfx::Point old_offset = bubble_border_->offset();
188 bubble_rect = bubble_border_->ComputeOffsetAndUpdateBubbleRect(bubble_rect,
189 anchor_rect);
190
191 // Repaints border if arrow offset is changed.
192 if (bubble_border_->offset() != old_offset)
193 GetBubbleFrameView()->SchedulePaint();
194
195 return bubble_rect;
196 }
197
198 void AppListView::QueryChanged(SearchBoxView* sender) { 179 void AppListView::QueryChanged(SearchBoxView* sender) {
199 string16 query; 180 string16 query;
200 TrimWhitespace(model_->search_box()->text(), TRIM_ALL, &query); 181 TrimWhitespace(model_->search_box()->text(), TRIM_ALL, &query);
201 bool should_show_search = !query.empty(); 182 bool should_show_search = !query.empty();
202 contents_view_->ShowSearchResults(should_show_search); 183 contents_view_->ShowSearchResults(should_show_search);
203 184
204 if (delegate_.get()) { 185 if (delegate_.get()) {
205 if (should_show_search) 186 if (should_show_search)
206 delegate_->StartSearch(); 187 delegate_->StartSearch();
207 else 188 else
208 delegate_->StopSearch(); 189 delegate_->StopSearch();
209 } 190 }
210 } 191 }
211 192
212 void AppListView::OpenResult(const SearchResult& result, int event_flags) { 193 void AppListView::OpenResult(const SearchResult& result, int event_flags) {
213 if (delegate_.get()) 194 if (delegate_.get())
214 delegate_->OpenSearchResult(result, event_flags); 195 delegate_->OpenSearchResult(result, event_flags);
215 } 196 }
216 197
217 void AppListView::InvokeResultAction(const SearchResult& result, 198 void AppListView::InvokeResultAction(const SearchResult& result,
218 int action_index, 199 int action_index,
219 int event_flags) { 200 int event_flags) {
220 if (delegate_.get()) 201 if (delegate_.get())
221 delegate_->InvokeSearchResultAction(result, action_index, event_flags); 202 delegate_->InvokeSearchResultAction(result, action_index, event_flags);
222 } 203 }
223 204
224 } // namespace app_list 205 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/app_list_view.h ('k') | ui/resources/default_100_percent/common/window_bubble_shadow_spike_big_left.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698