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 "chrome/browser/ui/views/location_bar/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 keyword_hint_view_(NULL), | 183 keyword_hint_view_(NULL), |
184 mic_search_view_(NULL), | 184 mic_search_view_(NULL), |
185 zoom_view_(NULL), | 185 zoom_view_(NULL), |
186 generated_credit_card_view_(NULL), | 186 generated_credit_card_view_(NULL), |
187 open_pdf_in_reader_view_(NULL), | 187 open_pdf_in_reader_view_(NULL), |
188 script_bubble_icon_view_(NULL), | 188 script_bubble_icon_view_(NULL), |
189 star_view_(NULL), | 189 star_view_(NULL), |
190 is_popup_mode_(is_popup_mode), | 190 is_popup_mode_(is_popup_mode), |
191 show_focus_rect_(false), | 191 show_focus_rect_(false), |
192 template_url_service_(NULL), | 192 template_url_service_(NULL), |
193 animation_offset_(0) { | 193 animation_offset_(0), |
194 weak_ptr_factory_(this) { | |
194 if (!views::Textfield::IsViewsTextfieldEnabled()) | 195 if (!views::Textfield::IsViewsTextfieldEnabled()) |
195 set_id(VIEW_ID_OMNIBOX); | 196 set_id(VIEW_ID_OMNIBOX); |
196 | 197 |
197 const int kOmniboxBorderImages[] = IMAGE_GRID(IDR_OMNIBOX_BORDER); | 198 const int kOmniboxBorderImages[] = IMAGE_GRID(IDR_OMNIBOX_BORDER); |
198 const int kOmniboxPopupImages[] = IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER); | 199 const int kOmniboxPopupImages[] = IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER); |
199 background_border_painter_.reset( | 200 background_border_painter_.reset( |
200 views::Painter::CreateImageGridPainter( | 201 views::Painter::CreateImageGridPainter( |
201 is_popup_mode_ ? kOmniboxPopupImages : kOmniboxBorderImages)); | 202 is_popup_mode_ ? kOmniboxPopupImages : kOmniboxBorderImages)); |
202 #if defined(OS_CHROMEOS) | 203 #if defined(OS_CHROMEOS) |
203 if (!is_popup_mode_) { | 204 if (!is_popup_mode_) { |
(...skipping 12 matching lines...) Expand all Loading... | |
216 | 217 |
217 if (browser_) | 218 if (browser_) |
218 browser_->search_model()->AddObserver(this); | 219 browser_->search_model()->AddObserver(this); |
219 } | 220 } |
220 | 221 |
221 LocationBarView::~LocationBarView() { | 222 LocationBarView::~LocationBarView() { |
222 if (template_url_service_) | 223 if (template_url_service_) |
223 template_url_service_->RemoveObserver(this); | 224 template_url_service_->RemoveObserver(this); |
224 if (browser_) | 225 if (browser_) |
225 browser_->search_model()->RemoveObserver(this); | 226 browser_->search_model()->RemoveObserver(this); |
227 weak_ptr_factory_.InvalidateWeakPtrs(); | |
sky
2013/09/04 16:20:12
Is there a reason you're explicitly invoking this?
dmazzoni
2013/09/04 17:16:18
It's sometimes safer, as they might not be invalid
| |
226 } | 228 } |
227 | 229 |
228 // static | 230 // static |
229 void LocationBarView::InitTouchableLocationBarChildView(views::View* view) { | 231 void LocationBarView::InitTouchableLocationBarChildView(views::View* view) { |
230 int horizontal_padding = GetBuiltInHorizontalPaddingForChildViews(); | 232 int horizontal_padding = GetBuiltInHorizontalPaddingForChildViews(); |
231 if (horizontal_padding != 0) { | 233 if (horizontal_padding != 0) { |
232 view->set_border(views::Border::CreateEmptyBorder( | 234 view->set_border(views::Border::CreateEmptyBorder( |
233 3, horizontal_padding, 3, horizontal_padding)); | 235 3, horizontal_padding, 3, horizontal_padding)); |
234 } | 236 } |
235 } | 237 } |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1293 // mid-point between two page actions in the bounding rectangle. For even | 1295 // mid-point between two page actions in the bounding rectangle. For even |
1294 // paddings, the +1 is dropped, which is right since there is no pixel at | 1296 // paddings, the +1 is dropped, which is right since there is no pixel at |
1295 // the mid-point. | 1297 // the mid-point. |
1296 bounds.Inset(-(horizontal_padding + 1) / 2, 0); | 1298 bounds.Inset(-(horizontal_padding + 1) / 2, 0); |
1297 location_bar_util::PaintExtensionActionBackground( | 1299 location_bar_util::PaintExtensionActionBackground( |
1298 *(*page_action_view)->image_view()->page_action(), | 1300 *(*page_action_view)->image_view()->page_action(), |
1299 tab_id, canvas, bounds, text_color, background_color); | 1301 tab_id, canvas, bounds, text_color, background_color); |
1300 } | 1302 } |
1301 } | 1303 } |
1302 | 1304 |
1305 void LocationBarView::AccessibilitySetValue(const string16& new_value) { | |
sky
2013/09/04 16:20:12
Make position match header.
dmazzoni
2013/09/04 17:16:18
The order was all over the place. I moved all of t
| |
1306 location_entry_->SetUserText(new_value); | |
sky
2013/09/04 16:20:12
Does this need to do nothing if is_popup_mode_, or
dmazzoni
2013/09/04 17:16:18
Good idea, I'll set the readonly flag if is_popup_
| |
1307 } | |
1308 | |
1303 const char* LocationBarView::GetClassName() const { | 1309 const char* LocationBarView::GetClassName() const { |
1304 return kViewClassName; | 1310 return kViewClassName; |
1305 } | 1311 } |
1306 | 1312 |
1307 bool LocationBarView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 1313 bool LocationBarView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
1308 #if defined(OS_WIN) | 1314 #if defined(OS_WIN) |
1309 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { | 1315 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { |
1310 if (location_entry_->model()->popup_model()->IsOpen()) { | 1316 if (location_entry_->model()->popup_model()->IsOpen()) { |
1311 // Return true so that the edit sees the tab and moves the selection. | 1317 // Return true so that the edit sees the tab and moves the selection. |
1312 return true; | 1318 return true; |
(...skipping 12 matching lines...) Expand all Loading... | |
1325 return omnibox_win->SkipDefaultKeyEventProcessing(event); | 1331 return omnibox_win->SkipDefaultKeyEventProcessing(event); |
1326 #endif // USE_AURA | 1332 #endif // USE_AURA |
1327 #endif // OS_WIN | 1333 #endif // OS_WIN |
1328 | 1334 |
1329 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in | 1335 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in |
1330 // src/ui/views/focus/focus_manager.cc for details. | 1336 // src/ui/views/focus/focus_manager.cc for details. |
1331 return false; | 1337 return false; |
1332 } | 1338 } |
1333 | 1339 |
1334 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { | 1340 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { |
1341 if (!location_entry_) | |
1342 return; | |
1343 | |
1335 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; | 1344 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; |
1336 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); | 1345 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); |
1337 state->value = location_entry_->GetText(); | 1346 state->value = location_entry_->GetText(); |
1338 | 1347 |
1339 string16::size_type entry_start; | 1348 string16::size_type entry_start; |
1340 string16::size_type entry_end; | 1349 string16::size_type entry_end; |
1341 location_entry_->GetSelectionBounds(&entry_start, &entry_end); | 1350 location_entry_->GetSelectionBounds(&entry_start, &entry_end); |
1342 state->selection_start = entry_start; | 1351 state->selection_start = entry_start; |
1343 state->selection_end = entry_end; | 1352 state->selection_end = entry_end; |
1353 | |
1354 state->set_value_callback = | |
1355 base::Bind(&LocationBarView::AccessibilitySetValue, | |
1356 weak_ptr_factory_.GetWeakPtr()); | |
1344 } | 1357 } |
1345 | 1358 |
1346 bool LocationBarView::HasFocus() const { | 1359 bool LocationBarView::HasFocus() const { |
1347 return location_entry_->model()->has_focus(); | 1360 return location_entry_->model()->has_focus(); |
1348 } | 1361 } |
1349 | 1362 |
1350 void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 1363 void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
1351 if (browser_ && browser_->instant_controller() && parent()) | 1364 if (browser_ && browser_->instant_controller() && parent()) |
1352 browser_->instant_controller()->SetOmniboxBounds(bounds()); | 1365 browser_->instant_controller()->SetOmniboxBounds(bounds()); |
1353 OmniboxPopupView* popup = location_entry_->model()->popup_model()->view(); | 1366 OmniboxPopupView* popup = location_entry_->model()->popup_model()->view(); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1553 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1566 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
1554 int total_height = | 1567 int total_height = |
1555 use_preferred_size ? GetPreferredSize().height() : height(); | 1568 use_preferred_size ? GetPreferredSize().height() : height(); |
1556 return std::max(total_height - (vertical_edge_thickness() * 2), 0); | 1569 return std::max(total_height - (vertical_edge_thickness() * 2), 0); |
1557 } | 1570 } |
1558 | 1571 |
1559 bool LocationBarView::HasValidSuggestText() const { | 1572 bool LocationBarView::HasValidSuggestText() const { |
1560 return suggested_text_view_->visible() && | 1573 return suggested_text_view_->visible() && |
1561 !suggested_text_view_->size().IsEmpty(); | 1574 !suggested_text_view_->size().IsEmpty(); |
1562 } | 1575 } |
OLD | NEW |