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

Side by Side Diff: views/controls/scrollbar/native_scroll_bar_win.cc

Issue 2812026: Auto-size the views version of the options dialog. (Closed)
Patch Set: Fix autosizing issue with gtk pref pages in chromeos options dialog. Created 10 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "views/controls/scrollbar/native_scroll_bar_win.h" 5 #include "views/controls/scrollbar/native_scroll_bar_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "app/win/window_impl.h" 10 #include "app/win/window_impl.h"
11 #include "base/keyboard_codes.h" 11 #include "base/keyboard_codes.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 DISALLOW_COPY_AND_ASSIGN(ScrollBarContainer); 193 DISALLOW_COPY_AND_ASSIGN(ScrollBarContainer);
194 }; 194 };
195 195
196 //////////////////////////////////////////////////////////////////////////////// 196 ////////////////////////////////////////////////////////////////////////////////
197 // NativeScrollBarWin, public: 197 // NativeScrollBarWin, public:
198 198
199 NativeScrollBarWin::NativeScrollBarWin(NativeScrollBar* scroll_bar) 199 NativeScrollBarWin::NativeScrollBarWin(NativeScrollBar* scroll_bar)
200 : native_scroll_bar_(scroll_bar), 200 : native_scroll_bar_(scroll_bar),
201 sb_container_(NULL) { 201 sb_container_(NULL) {
202 set_focus_view(scroll_bar); 202 set_focus_view(scroll_bar);
203 memset(&scroll_info_, 0, sizeof(scroll_info_));
203 } 204 }
204 205
205 NativeScrollBarWin::~NativeScrollBarWin() { 206 NativeScrollBarWin::~NativeScrollBarWin() {
206 if (sb_container_) { 207 if (sb_container_.get()) {
207 // We always destroy the scrollbar container explicitly to cover all 208 // We always destroy the scrollbar container explicitly to cover all
208 // cases including when the container is no longer connected to a 209 // cases including when the container is no longer connected to a
209 // widget tree. 210 // widget tree.
210 DestroyWindow(sb_container_->hwnd()); 211 DestroyWindow(sb_container_->hwnd());
211 delete sb_container_;
212 } 212 }
213 } 213 }
214 214
215 //////////////////////////////////////////////////////////////////////////////// 215 ////////////////////////////////////////////////////////////////////////////////
216 // NativeScrollBarWin, View overrides: 216 // NativeScrollBarWin, View overrides:
217 217
218 void NativeScrollBarWin::Layout() { 218 void NativeScrollBarWin::Layout() {
219 SetBounds(native_scroll_bar_->GetLocalBounds(true)); 219 SetBounds(native_scroll_bar_->GetLocalBounds(true));
220 NativeControlWin::Layout(); 220 NativeControlWin::Layout();
221 } 221 }
222 222
223 gfx::Size NativeScrollBarWin::GetPreferredSize() { 223 gfx::Size NativeScrollBarWin::GetPreferredSize() {
224 if (native_scroll_bar_->IsHorizontal()) 224 if (native_scroll_bar_->IsHorizontal())
225 return gfx::Size(0, GetHorizontalScrollBarHeight()); 225 return gfx::Size(0, GetHorizontalScrollBarHeight());
226 return gfx::Size(GetVerticalScrollBarWidth(), 0); 226 return gfx::Size(GetVerticalScrollBarWidth(), 0);
227 } 227 }
228 228
229 bool NativeScrollBarWin::OnKeyPressed(const KeyEvent& event) { 229 bool NativeScrollBarWin::OnKeyPressed(const KeyEvent& event) {
230 if (!sb_container_) 230 if (!sb_container_.get())
231 return false; 231 return false;
232 int code = -1; 232 int code = -1;
233 switch (event.GetKeyCode()) { 233 switch (event.GetKeyCode()) {
234 case base::VKEY_UP: 234 case base::VKEY_UP:
235 if (!native_scroll_bar_->IsHorizontal()) 235 if (!native_scroll_bar_->IsHorizontal())
236 code = SB_LINEUP; 236 code = SB_LINEUP;
237 break; 237 break;
238 case base::VKEY_PRIOR: 238 case base::VKEY_PRIOR:
239 code = SB_PAGEUP; 239 code = SB_PAGEUP;
240 break; 240 break;
(...skipping 22 matching lines...) Expand all
263 if (code != -1) { 263 if (code != -1) {
264 SendMessage(sb_container_->hwnd(), 264 SendMessage(sb_container_->hwnd(),
265 native_scroll_bar_->IsHorizontal() ? WM_HSCROLL : WM_VSCROLL, 265 native_scroll_bar_->IsHorizontal() ? WM_HSCROLL : WM_VSCROLL,
266 MAKELONG(static_cast<WORD>(code), 0), 0L); 266 MAKELONG(static_cast<WORD>(code), 0), 0L);
267 return true; 267 return true;
268 } 268 }
269 return false; 269 return false;
270 } 270 }
271 271
272 bool NativeScrollBarWin::OnMouseWheel(const MouseWheelEvent& e) { 272 bool NativeScrollBarWin::OnMouseWheel(const MouseWheelEvent& e) {
273 if (!sb_container_) 273 if (!sb_container_.get())
274 return false; 274 return false;
275 sb_container_->ScrollWithOffset(e.GetOffset()); 275 sb_container_->ScrollWithOffset(e.GetOffset());
276 return true; 276 return true;
277 } 277 }
278 278
279 //////////////////////////////////////////////////////////////////////////////// 279 ////////////////////////////////////////////////////////////////////////////////
280 // NativeScrollBarWin, NativeControlWin overrides: 280 // NativeScrollBarWin, NativeControlWin overrides:
281 281
282 void NativeScrollBarWin::CreateNativeControl() { 282 void NativeScrollBarWin::CreateNativeControl() {
283 sb_container_ = new ScrollBarContainer(native_scroll_bar_); 283 sb_container_.reset(new ScrollBarContainer(native_scroll_bar_));
284 NativeControlCreated(sb_container_->hwnd()); 284 NativeControlCreated(sb_container_->hwnd());
285 // Reinstall scroll state if we have valid information.
286 if (scroll_info_.cbSize)
287 SetScrollInfo(sb_container_->GetScrollBarHWND(), SB_CTL, &scroll_info_,
288 TRUE);
285 } 289 }
286 290
287 //////////////////////////////////////////////////////////////////////////////// 291 ////////////////////////////////////////////////////////////////////////////////
288 // NativeScrollBarWin, NativeScrollBarWrapper overrides: 292 // NativeScrollBarWin, NativeScrollBarWrapper overrides:
289 293
290 int NativeScrollBarWin::GetPosition() const { 294 int NativeScrollBarWin::GetPosition() const {
291 SCROLLINFO si; 295 SCROLLINFO si;
292 si.cbSize = sizeof(si); 296 si.cbSize = sizeof(si);
293 si.fMask = SIF_POS; 297 si.fMask = SIF_POS;
294 GetScrollInfo(sb_container_->GetScrollBarHWND(), SB_CTL, &si); 298 GetScrollInfo(sb_container_->GetScrollBarHWND(), SB_CTL, &si);
295 return si.nPos; 299 return si.nPos;
296 } 300 }
297 301
298 View* NativeScrollBarWin::GetView() { 302 View* NativeScrollBarWin::GetView() {
299 return this; 303 return this;
300 } 304 }
301 305
302 void NativeScrollBarWin::Update(int viewport_size, 306 void NativeScrollBarWin::Update(int viewport_size,
303 int content_size, 307 int content_size,
304 int current_pos) { 308 int current_pos) {
305 if (!sb_container_) 309 if (!sb_container_.get())
306 return; 310 return;
307 311
308 if (content_size < 0) 312 if (content_size < 0)
309 content_size = 0; 313 content_size = 0;
310 314
311 if (current_pos < 0) 315 if (current_pos < 0)
312 current_pos = 0; 316 current_pos = 0;
313 317
314 if (current_pos > content_size) 318 if (current_pos > content_size)
315 current_pos = content_size; 319 current_pos = content_size;
316 320
317 SCROLLINFO si; 321 scroll_info_.cbSize = sizeof(scroll_info_);
318 si.cbSize = sizeof(si); 322 scroll_info_.fMask = SIF_DISABLENOSCROLL | SIF_POS | SIF_RANGE | SIF_PAGE;
319 si.fMask = SIF_DISABLENOSCROLL | SIF_POS | SIF_RANGE | SIF_PAGE; 323 scroll_info_.nMin = 0;
320 si.nMin = 0; 324 scroll_info_.nMax = content_size;
321 si.nMax = content_size; 325 scroll_info_.nPos = current_pos;
322 si.nPos = current_pos; 326 scroll_info_.nPage = viewport_size;
323 si.nPage = viewport_size; 327 SetScrollInfo(sb_container_->GetScrollBarHWND(), SB_CTL, &scroll_info_, TRUE);
324 SetScrollInfo(sb_container_->GetScrollBarHWND(), SB_CTL, &si, TRUE);
325 } 328 }
326 329
327 //////////////////////////////////////////////////////////////////////////////// 330 ////////////////////////////////////////////////////////////////////////////////
328 // NativewScrollBarWrapper, public: 331 // NativewScrollBarWrapper, public:
329 332
330 // static 333 // static
331 NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper( 334 NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper(
332 NativeScrollBar* scroll_bar) { 335 NativeScrollBar* scroll_bar) {
333 return new NativeScrollBarWin(scroll_bar); 336 return new NativeScrollBarWin(scroll_bar);
334 } 337 }
335 338
336 // static 339 // static
337 int NativeScrollBarWrapper::GetHorizontalScrollBarHeight() { 340 int NativeScrollBarWrapper::GetHorizontalScrollBarHeight() {
338 return GetSystemMetrics(SM_CYHSCROLL); 341 return GetSystemMetrics(SM_CYHSCROLL);
339 } 342 }
340 343
341 // static 344 // static
342 int NativeScrollBarWrapper::GetVerticalScrollBarWidth() { 345 int NativeScrollBarWrapper::GetVerticalScrollBarWidth() {
343 return GetSystemMetrics(SM_CXVSCROLL); 346 return GetSystemMetrics(SM_CXVSCROLL);
344 } 347 }
345 348
346 } // namespace views 349 } // namespace views
347
OLDNEW
« no previous file with comments | « views/controls/scrollbar/native_scroll_bar_win.h ('k') | views/controls/tabbed_pane/native_tabbed_pane_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698