Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_TOUCHABLE_LOCATION_BAR_VIEW_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_TOUCHABLE_LOCATION_BAR_VIEW_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | |
| 10 #include "ui/base/layout.h" | |
| 11 #include "ui/views/border.h" | |
| 12 | |
| 13 // A mix-in for a class based on views::View and intended for the | |
| 14 // location bar. In a touch layout, the mix-in adds an empty border | |
| 15 // around the view to increase the size of the touch target. The | |
| 16 // border extends a few pixels up and down, which doesn't affect | |
| 17 // layout, and extends half of the padding used between items in the | |
| 18 // location bar to the left and right. | |
| 19 // | |
| 20 // To make your location bar View named FooBlat extend itself into the | |
| 21 // padding around it to get an enlarged touch target, inherit from | |
| 22 // TouchableLocationBarView<FooBlat> and call | |
| 23 // TouchableLocationBarView<FooBlat>::Init() from your constructor. | |
| 24 template<class Concrete> | |
| 25 class TouchableLocationBarView { | |
| 26 public: | |
| 27 // Call this from the constructor (or during early initialization) | |
| 28 // of a class that inherits from TouchableLocationBarView<>. | |
| 29 void Init(); | |
| 30 | |
| 31 // Returns the number of pixels of built-in padding to the left and | |
| 32 // right of the image for this view. | |
| 33 int GetBuiltInHorizontalPadding() const; | |
| 34 }; | |
| 35 | |
| 36 template<class Concrete> | |
| 37 int TouchableLocationBarView<Concrete>::GetBuiltInHorizontalPadding() const { | |
| 38 return ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ? | |
| 39 LocationBarView::GetItemPadding() / 2 : 0; | |
| 40 } | |
| 41 | |
| 42 template<class Concrete> | |
| 43 void TouchableLocationBarView<Concrete>::Init() { | |
|
Peter Kasting
2012/06/13 17:09:16
Nit: Order definitions the same as the declaration
Jói
2012/06/13 17:18:01
Done.
| |
| 44 int horizontal_padding = GetBuiltInHorizontalPadding(); | |
| 45 if (horizontal_padding != 0) { | |
| 46 static_cast<Concrete*>(this)->set_border(views::Border::CreateEmptyBorder( | |
| 47 3, horizontal_padding, 3, horizontal_padding)); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_TOUCHABLE_LOCATION_BAR_VIEW_H_ | |
| OLD | NEW |