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

Side by Side Diff: ui/views/demo/main.cc

Issue 6541030: View API/implementation cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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
« no previous file with comments | « no previous file | ui/views/events/event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <windows.h> 5 #include <windows.h>
6 #include <atlbase.h> 6 #include <atlbase.h>
7 #include <atlapp.h> 7 #include <atlapp.h>
8 #include <atlcrack.h> 8 #include <atlcrack.h>
9 #include <atlmisc.h> 9 #include <atlmisc.h>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 : ColorView(SK_ColorMAGENTA), 81 : ColorView(SK_ColorMAGENTA),
82 c1_(new ColorView(SK_ColorGREEN)), 82 c1_(new ColorView(SK_ColorGREEN)),
83 c2_(new ColorView(SK_ColorRED)) { 83 c2_(new ColorView(SK_ColorRED)) {
84 AddChildView(c1_); 84 AddChildView(c1_);
85 AddChildView(c2_); 85 AddChildView(c2_);
86 } 86 }
87 virtual ~FancyPantsView() {} 87 virtual ~FancyPantsView() {}
88 88
89 // Overridden from ui::View: 89 // Overridden from ui::View:
90 virtual void Layout() { 90 virtual void Layout() {
91 c1_->SetBounds(20, 20, width() - 40, height() - 40); 91 c1_->SetBounds(gfx::Rect(20, 20, std::max(width() - 40, 0),
92 c2_->SetBounds(50, 50, 50, 50); 92 std::max(height() - 40, 0)));
93 c2_->SetBounds(gfx::Rect(50, 50, 50, 50));
93 Invalidate(); 94 Invalidate();
94 } 95 }
95 virtual bool OnMousePressed(const ui::MouseEvent& event) { 96 virtual bool OnMousePressed(const ui::MouseEvent& event) {
96 old_color_ = color(); 97 old_color_ = color();
97 set_color(SK_ColorWHITE); 98 set_color(SK_ColorWHITE);
98 mouse_offset_ = event.location(); 99 mouse_offset_ = event.location();
99 return true; 100 return true;
100 } 101 }
101 virtual bool OnMouseDragged(const ui::MouseEvent& event) { 102 virtual bool OnMouseDragged(const ui::MouseEvent& event) {
102 gfx::Rect old_bounds = bounds(); 103 gfx::Rect old_bounds = bounds();
103 SetPosition(gfx::Point(event.x() - mouse_offset_.x(), 104 SetOrigin(gfx::Point(event.x() - mouse_offset_.x(),
104 event.y() - mouse_offset_.y())); 105 event.y() - mouse_offset_.y()));
105 gfx::Rect new_bounds = bounds(); 106 gfx::Rect new_bounds = bounds();
106 parent()->InvalidateRect(old_bounds.Union(new_bounds)); 107 parent()->InvalidateRect(old_bounds.Union(new_bounds));
107 return true; 108 return true;
108 } 109 }
109 virtual void OnMouseReleased(const ui::MouseEvent& event) { 110 virtual void OnMouseReleased(const ui::MouseEvent& event) {
110 set_color(old_color_); 111 set_color(old_color_);
111 } 112 }
112 virtual void OnMouseCaptureLost() { 113 virtual void OnMouseCaptureLost() {
113 set_color(SK_ColorYELLOW); 114 set_color(SK_ColorYELLOW);
114 } 115 }
(...skipping 13 matching lines...) Expand all
128 class ContentsView : public ColorView { 129 class ContentsView : public ColorView {
129 public: 130 public:
130 ContentsView() 131 ContentsView()
131 : c1_(new ColorView(SK_ColorBLUE)), 132 : c1_(new ColorView(SK_ColorBLUE)),
132 c2_(new ColorView(SK_ColorGREEN)), 133 c2_(new ColorView(SK_ColorGREEN)),
133 c3_(new FancyPantsView()), 134 c3_(new FancyPantsView()),
134 ColorView(SK_ColorRED) { 135 ColorView(SK_ColorRED) {
135 set_parent_owned(false); 136 set_parent_owned(false);
136 AddChildView(c1_); 137 AddChildView(c1_);
137 AddChildView(c2_); 138 AddChildView(c2_);
138 c3_->SetPosition(gfx::Point(200, 200)); 139 c3_->SetOrigin(gfx::Point(200, 200));
139 AddChildView(c3_); 140 AddChildView(c3_);
140 } 141 }
141 142
142 virtual ~ContentsView() {} 143 virtual ~ContentsView() {}
143 144
144 void Init() { 145 void Init() {
145 //c3_->SetHasLayer(true); 146 //c3_->SetHasLayer(true);
146 } 147 }
147 148
148 private: 149 private:
149 // Overridden from ui::View: 150 // Overridden from ui::View:
150 virtual void Layout() { 151 virtual void Layout() {
151 c1_->SetBounds(20, 20, width() - 40, height() - 40); 152 c1_->SetBounds(gfx::Rect(20, 20, std::max(width() - 40, 0),
152 c2_->SetBounds(50, 50, 50, 50); 153 std::max(height() - 40, 0)));
154 c2_->SetBounds(gfx::Rect(50, 50, 50, 50));
153 c3_->SetSize(gfx::Size(75, 75)); 155 c3_->SetSize(gfx::Size(75, 75));
154 Invalidate(); 156 Invalidate();
155 } 157 }
156 158
157 View* c1_; 159 View* c1_;
158 View* c2_; 160 View* c2_;
159 FancyPantsView* c3_; 161 FancyPantsView* c3_;
160 }; 162 };
161 163
162 int main(int argc, char **argv) { 164 int main(int argc, char **argv) {
163 OleInitialize(NULL); 165 OleInitialize(NULL);
164 base::AtExitManager exit_manager; 166 base::AtExitManager exit_manager;
165 MessageLoop main_message_loop(MessageLoop::TYPE_UI); 167 MessageLoop main_message_loop(MessageLoop::TYPE_UI);
166 168
167 ContentsView cv; 169 ContentsView cv;
168 ui::Widget widget(&cv); 170 ui::Widget widget(&cv);
169 widget.InitWithNativeViewParent(NULL, gfx::Rect(20, 20, 400, 400)); 171 widget.InitWithNativeViewParent(NULL, gfx::Rect(20, 20, 400, 400));
170 cv.Init(); 172 cv.Init();
171 widget.Show(); 173 widget.Show();
172 174
173 V2DemoDispatcher dispatcher; 175 V2DemoDispatcher dispatcher;
174 MessageLoopForUI::current()->Run(&dispatcher); 176 MessageLoopForUI::current()->Run(&dispatcher);
175 177
176 OleUninitialize(); 178 OleUninitialize();
177 } 179 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698