blob: 019bb77f48f77e16c545f606fd3bdb5418cbb016 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
#define VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
#pragma once
// TODO(avi): remove when not needed
#include "base/utf_string_conversions.h"
#include "ui/gfx/font.h"
#include "views/controls/button/button.h"
#include "views/controls/button/native_button_wrapper.h"
#if defined(TOUCH_UI)
#include "views/controls/button/text_button.h"
#endif
namespace gfx {
class Font;
}
namespace views {
class NativeButtonBase : public Button {
public:
// The button's class name.
static const char kViewClassName[];
explicit NativeButtonBase(ButtonListener* listener);
NativeButtonBase(ButtonListener* listener, const std::wstring& label);
virtual ~NativeButtonBase();
// Sets/Gets the text to be used as the button's label.
virtual void SetLabel(const std::wstring& label);
std::wstring label() const { return UTF16ToWideHack(label_); }
// Sets the font to be used when displaying the button's label.
void set_font(const gfx::Font& font) { font_ = font; }
const gfx::Font& font() const { return font_; }
// Sets/Gets whether or not the button appears and behaves as the default
// button in its current context.
void SetIsDefault(bool default_button);
bool is_default() const { return is_default_; }
// Sets/Gets whether or not pressing this button requires elevation.
void SetNeedElevation(bool need_elevation);
bool need_elevation() const { return need_elevation_; }
void set_ignore_minimum_size(bool ignore_minimum_size) {
ignore_minimum_size_ = ignore_minimum_size;
}
// Called by the wrapper when the actual wrapped native button was pressed.
void ButtonPressed();
// Overridden from View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual void Layout() OVERRIDE;
virtual void SetEnabled(bool flag) OVERRIDE;
virtual void OnFocus() OVERRIDE;
virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
protected:
virtual void ViewHierarchyChanged(bool is_add, View* parent,
View* child) OVERRIDE;
virtual std::string GetClassName() const OVERRIDE;
virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE;
// Create the button wrapper and returns it. Ownership of the returned
// value is passed to the caller.
//
// This can be overridden by subclass to create a wrapper of a particular
// type. See NativeButtonWrapper interface for types.
virtual NativeButtonWrapper* CreateWrapper();
// Sets a border to the button. Override to set a different border or to not
// set one (the default is 0,8,0,8 for push buttons).
virtual void InitBorder();
// The object that actually implements the native button.
NativeButtonWrapper* native_wrapper_;
private:
// Update all states.
void UpdateAllStates();
// The button label.
string16 label_;
// True if the button is the default button in its context.
bool is_default_;
// True if this button requires elevation (or sudo). This flag is currently
// used for adding a shield icon on Windows Vista or later.
bool need_elevation_;
// The font used to render the button label.
gfx::Font font_;
// True if the button should ignore the minimum size for the platform. Default
// is false. Set to true to create narrower buttons.
bool ignore_minimum_size_;
DISALLOW_COPY_AND_ASSIGN(NativeButtonBase);
};
#if defined(TOUCH_UI)
// TODO(saintlou): this maps NativeButton to TextButton in the touch case
class NativeButton : public TextButton {
public:
NativeButton(ButtonListener* listener, const std::wstring& label);
void SetLabel(const std::wstring& label);
void set_font(const gfx::Font& font);
void SetIsDefault(bool default_button);
bool is_default() const;
void set_ignore_minimum_size(bool);
private:
// True if the button is the default button in its context.
bool is_default_;
DISALLOW_COPY_AND_ASSIGN(NativeButton);
};
#else
// TODO(saintlou): Windows and Clang do not like typedef, it
// chokes in other modules that have a forward declaration for
// NativeButton
class NativeButton : public NativeButtonBase {
public:
explicit NativeButton(ButtonListener* listener);
NativeButton(ButtonListener* listener, const std::wstring& label);
virtual ~NativeButton();
private:
DISALLOW_COPY_AND_ASSIGN(NativeButton);
};
#endif
} // namespace views
#endif // VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
|