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

Side by Side Diff: ui/gfx/rect.cc

Issue 10704198: Scale to DIPs in ppb_graphics2d_impl for proper invalidation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make generic ScaleBounds method, handle scroll properly Created 8 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 | Annotate | Revision Log
OLDNEW
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 "ui/gfx/rect.h" 5 #include "ui/gfx/rect.h"
6 6
7 #include <math.h>
8
7 #if defined(OS_WIN) 9 #if defined(OS_WIN)
8 #include <windows.h> 10 #include <windows.h>
9 #elif defined(OS_MACOSX) 11 #elif defined(OS_MACOSX)
10 #include <ApplicationServices/ApplicationServices.h> 12 #include <ApplicationServices/ApplicationServices.h>
11 #elif defined(TOOLKIT_GTK) 13 #elif defined(TOOLKIT_GTK)
12 #include <gdk/gdk.h> 14 #include <gdk/gdk.h>
13 #endif 15 #endif
14 16
15 #include "base/logging.h" 17 #include "base/logging.h"
16 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
(...skipping 20 matching lines...) Expand all
37 Rect::Rect(const gfx::Size& size) 39 Rect::Rect(const gfx::Size& size)
38 : RectBaseT(size) { 40 : RectBaseT(size) {
39 } 41 }
40 42
41 Rect::Rect(const gfx::Point& origin, const gfx::Size& size) 43 Rect::Rect(const gfx::Point& origin, const gfx::Size& size)
42 : RectBaseT(origin, size) { 44 : RectBaseT(origin, size) {
43 } 45 }
44 46
45 Rect::~Rect() {} 47 Rect::~Rect() {}
46 48
49 void Rect::ScaleBounds(float scale) {
50 int left = static_cast<int>(floorf(x() * scale));
51 int top = static_cast<int>(floorf(y() * scale));
52 int right = static_cast<int>(ceilf((x() + width()) * scale));
53 int bottom = static_cast<int>(ceilf((y() + height()) * scale));
54 SetRect(left, top, right - left, bottom - top);
55 }
56
47 #if defined(OS_WIN) 57 #if defined(OS_WIN)
48 Rect::Rect(const RECT& r) 58 Rect::Rect(const RECT& r)
49 : RectBaseT(gfx::Point(r.left, r.top)) { 59 : RectBaseT(gfx::Point(r.left, r.top)) {
50 set_width(std::abs(r.right - r.left)); 60 set_width(std::abs(r.right - r.left));
51 set_height(std::abs(r.bottom - r.top)); 61 set_height(std::abs(r.bottom - r.top));
52 } 62 }
53 63
54 Rect& Rect::operator=(const RECT& r) { 64 Rect& Rect::operator=(const RECT& r) {
55 set_x(r.left); 65 set_x(r.left);
56 set_y(r.top); 66 set_y(r.top);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 118 }
109 #endif 119 #endif
110 120
111 std::string Rect::ToString() const { 121 std::string Rect::ToString() const {
112 return base::StringPrintf("%s %s", 122 return base::StringPrintf("%s %s",
113 origin().ToString().c_str(), 123 origin().ToString().c_str(),
114 size().ToString().c_str()); 124 size().ToString().c_str());
115 } 125 }
116 126
117 } // namespace gfx 127 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698