summaryrefslogtreecommitdiffstats
path: root/chrome/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-17 19:33:09 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-17 19:33:09 +0000
commit0a1d36b22de76ac7d8e0af2efb222c5ae85d099b (patch)
treef3c3a1bb493dd98baaec6489dcc3b35eb93694da /chrome/views
parent251b16cffbfca46fd038b13c702d9309d0948eb0 (diff)
downloadchromium_src-0a1d36b22de76ac7d8e0af2efb222c5ae85d099b.zip
chromium_src-0a1d36b22de76ac7d8e0af2efb222c5ae85d099b.tar.gz
chromium_src-0a1d36b22de76ac7d8e0af2efb222c5ae85d099b.tar.bz2
Convert SchedulePaint and a few other methods to use gfx types.
http://crbug.com/2186 Review URL: http://codereview.chromium.org/7468 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3550 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r--chrome/views/container.h6
-rw-r--r--chrome/views/container_win.cc15
-rw-r--r--chrome/views/container_win.h2
-rw-r--r--chrome/views/custom_frame_window.cc2
-rw-r--r--chrome/views/root_view.cc42
-rw-r--r--chrome/views/root_view.h8
-rw-r--r--chrome/views/scroll_view.cc4
-rw-r--r--chrome/views/tooltip_manager.cc4
-rw-r--r--chrome/views/view.cc23
-rw-r--r--chrome/views/view.h37
10 files changed, 61 insertions, 82 deletions
diff --git a/chrome/views/container.h b/chrome/views/container.h
index e10b409..08f776c 100644
--- a/chrome/views/container.h
+++ b/chrome/views/container.h
@@ -8,6 +8,10 @@
// TODO(maruel): Remove once HWND is abstracted.
#include <windows.h>
+namespace gfx {
+class Rect;
+}
+
// TODO(maruel): Remove once gfx::Rect is used instead.
namespace WTL {
class CRect;
@@ -56,7 +60,7 @@ class Container {
virtual HWND GetHWND() const = 0;
// Forces a paint of a specified rectangle immediately.
- virtual void PaintNow(const CRect& update_rect) = 0;
+ virtual void PaintNow(const gfx::Rect& update_rect) = 0;
// Returns the RootView contained by this container
virtual RootView* GetRootView() = 0;
diff --git a/chrome/views/container_win.cc b/chrome/views/container_win.cc
index 7c0239d..59e1199 100644
--- a/chrome/views/container_win.cc
+++ b/chrome/views/container_win.cc
@@ -247,13 +247,13 @@ HWND ContainerWin::GetHWND() const {
return hwnd_;
}
-void ContainerWin::PaintNow(const CRect& update_rect) {
+void ContainerWin::PaintNow(const gfx::Rect& update_rect) {
if (layered_) {
PaintLayeredWindow();
} else if (root_view_->NeedsPainting(false) && IsWindow()) {
if (!opaque_ && GetParent()) {
// We're transparent. Need to force painting to occur from our parent.
- CRect parent_update_rect = update_rect;
+ CRect parent_update_rect = update_rect.ToRECT();
POINT location_in_parent = { 0, 0 };
ClientToScreen(hwnd_, &location_in_parent);
::ScreenToClient(GetParent(), &location_in_parent);
@@ -261,7 +261,8 @@ void ContainerWin::PaintNow(const CRect& update_rect) {
::RedrawWindow(GetParent(), parent_update_rect, NULL,
RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN);
} else {
- RedrawWindow(hwnd_, update_rect, NULL,
+ RECT native_update_rect = update_rect.ToRECT();
+ RedrawWindow(hwnd_, &native_update_rect, NULL,
RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN);
}
// As we were created with a style of WS_CLIPCHILDREN redraw requests may
@@ -805,7 +806,7 @@ void ContainerWin::ChangeSize(UINT size_param, const CSize& size) {
root_view_->SchedulePaint();
if (layered_)
- PaintNow(rect);
+ PaintNow(gfx::Rect(rect));
}
RootView* ContainerWin::CreateRootView() {
@@ -826,9 +827,9 @@ void ContainerWin::PaintLayeredWindow() {
// call to UpdateLayeredWindow updates the entire window, not just the
// cliprect.
contents_->save(SkCanvas::kClip_SaveFlag);
- CRect dirty_rect = root_view_->GetScheduledPaintRect();
- contents_->ClipRectInt(
- dirty_rect.left, dirty_rect.top, dirty_rect.Width(), dirty_rect.Height());
+ gfx::Rect dirty_rect = root_view_->GetScheduledPaintRect();
+ contents_->ClipRectInt(dirty_rect.x(), dirty_rect.y(), dirty_rect.width(),
+ dirty_rect.height());
root_view_->ProcessPaint(contents_.get());
contents_->restore();
diff --git a/chrome/views/container_win.h b/chrome/views/container_win.h
index 5df6529..a5f55f8 100644
--- a/chrome/views/container_win.h
+++ b/chrome/views/container_win.h
@@ -241,7 +241,7 @@ class ContainerWin : public Container,
virtual void GetBounds(CRect *out, bool including_frame) const;
virtual void MoveToFront(bool should_activate);
virtual HWND GetHWND() const;
- virtual void PaintNow(const CRect& update_rect);
+ virtual void PaintNow(const gfx::Rect& update_rect);
virtual RootView* GetRootView();
virtual bool IsVisible();
virtual bool IsActive();
diff --git a/chrome/views/custom_frame_window.cc b/chrome/views/custom_frame_window.cc
index f45731f..472a9bb 100644
--- a/chrome/views/custom_frame_window.cc
+++ b/chrome/views/custom_frame_window.cc
@@ -1157,7 +1157,7 @@ void CustomFrameWindow::OnNCPaint(HRGN rgn) {
UnionRect(&dirty_region, &tmp, &old_paint_region);
}
- root_view->SchedulePaint(dirty_region, false);
+ root_view->SchedulePaint(gfx::Rect(dirty_region), false);
// ChromeCanvasPaints destructor does the actual painting. As such, wrap the
// following in a block to force paint to occur so that we can release the dc.
diff --git a/chrome/views/root_view.cc b/chrome/views/root_view.cc
index 80abe75..33597f9 100644
--- a/chrome/views/root_view.cc
+++ b/chrome/views/root_view.cc
@@ -53,7 +53,6 @@ const char RootView::kViewClassName[] = "chrome/views/RootView";
RootView::RootView(Container* container)
: container_(container),
- invalid_rect_(0,0,0,0),
mouse_pressed_handler_(NULL),
mouse_move_handler_(NULL),
explicit_mouse_handler_(FALSE),
@@ -91,14 +90,14 @@ RootView::~RootView() {
//
/////////////////////////////////////////////////////////////////////////////
-void RootView::SchedulePaint(const CRect& r, bool urgent) {
+void RootView::SchedulePaint(const gfx::Rect& r, bool urgent) {
// If there is an existing invalid rect, add the union of the scheduled
// rect with the invalid rect. This could be optimized further if
// necessary.
- if (invalid_rect_.IsRectNull())
+ if (invalid_rect_.IsEmpty())
invalid_rect_ = r;
else
- invalid_rect_.UnionRect(invalid_rect_, r);
+ invalid_rect_ = invalid_rect_.Union(r);
if (urgent || invalid_rect_urgent_) {
invalid_rect_urgent_ = true;
@@ -146,9 +145,9 @@ void RootView::ProcessPaint(ChromeCanvas* canvas) {
// Clip the invalid rect to our bounds. If a view is in a scrollview
// it could be a lot larger
- invalid_rect_ = GetScheduledPaintRectConstrainedToSize();
+ invalid_rect_ = gfx::Rect(GetScheduledPaintRectConstrainedToSize());
- if (invalid_rect_.IsRectNull())
+ if (invalid_rect_.IsEmpty())
return;
// Clear the background.
@@ -158,9 +157,10 @@ void RootView::ProcessPaint(ChromeCanvas* canvas) {
canvas->save();
// Set the clip rect according to the invalid rect.
- int clip_x = invalid_rect_.left + x();
- int clip_y = invalid_rect_.top + y();
- canvas->ClipRectInt(clip_x, clip_y, invalid_rect_.Width(), invalid_rect_.Height());
+ int clip_x = invalid_rect_.x() + x();
+ int clip_y = invalid_rect_.y() + y();
+ canvas->ClipRectInt(clip_x, clip_y, invalid_rect_.width(),
+ invalid_rect_.height());
// Paint the tree
View::ProcessPaint(canvas);
@@ -184,7 +184,7 @@ void RootView::PaintNow() {
}
bool RootView::NeedsPainting(bool urgent) {
- bool has_invalid_rect = !invalid_rect_.IsRectNull();
+ bool has_invalid_rect = !invalid_rect_.IsEmpty();
if (urgent) {
if (invalid_rect_urgent_)
return has_invalid_rect;
@@ -195,18 +195,15 @@ bool RootView::NeedsPainting(bool urgent) {
}
}
-const CRect& RootView::GetScheduledPaintRect() {
+const gfx::Rect& RootView::GetScheduledPaintRect() {
return invalid_rect_;
}
-CRect RootView::GetScheduledPaintRectConstrainedToSize() {
- if (invalid_rect_.IsRectEmpty())
- return invalid_rect_;
+RECT RootView::GetScheduledPaintRectConstrainedToSize() {
+ if (invalid_rect_.IsEmpty())
+ return invalid_rect_.ToRECT();
- CRect local_bounds = GetLocalBounds(true).ToRECT();
- CRect invalid_rect;
- invalid_rect.IntersectRect(&invalid_rect_, &local_bounds);
- return invalid_rect;
+ return invalid_rect_.Intersect(GetLocalBounds(true)).ToRECT();
}
/////////////////////////////////////////////////////////////////////////////
@@ -889,7 +886,7 @@ std::string RootView::GetClassName() const {
}
void RootView::ClearPaintRect() {
- invalid_rect_.SetRectEmpty();
+ invalid_rect_.SetRect(0, 0, 0, 0);
// This painting has been done. Reset the urgent flag.
invalid_rect_urgent_ = false;
@@ -899,9 +896,8 @@ void RootView::ClearPaintRect() {
}
void RootView::OnPaint(HWND hwnd) {
- CRect original_dirty_region =
- GetScheduledPaintRectConstrainedToSize();
- if (!original_dirty_region.IsRectEmpty()) {
+ RECT original_dirty_region = GetScheduledPaintRectConstrainedToSize();
+ if (!!IsRectEmpty(&original_dirty_region)) {
// Invoke InvalidateRect so that the dirty region of the window includes the
// region we need to paint. If we didn't do this and the region didn't
// include the dirty region, ProcessPaint would incorrectly mark everything
@@ -912,7 +908,7 @@ void RootView::OnPaint(HWND hwnd) {
ChromeCanvasPaint canvas(hwnd);
if (!canvas.isEmpty()) {
const PAINTSTRUCT& ps = canvas.paintStruct();
- SchedulePaint(ps.rcPaint, false);
+ SchedulePaint(gfx::Rect(ps.rcPaint), false);
if (NeedsPainting(false))
ProcessPaint(&canvas);
}
diff --git a/chrome/views/root_view.h b/chrome/views/root_view.h
index eef96eb..d15d354 100644
--- a/chrome/views/root_view.h
+++ b/chrome/views/root_view.h
@@ -51,7 +51,7 @@ class RootView : public View,
// Layout and Painting functions
// Overridden from View to implement paint scheduling.
- virtual void SchedulePaint(const CRect& r, bool urgent);
+ virtual void SchedulePaint(const gfx::Rect& r, bool urgent);
// Convenience to schedule the whole view
virtual void SchedulePaint();
@@ -73,10 +73,10 @@ class RootView : public View,
// Invoked by the Container to discover what rectangle should be
// painted
- const CRect& GetScheduledPaintRect();
+ const gfx::Rect& GetScheduledPaintRect();
// Returns the region scheduled to paint clipped to the RootViews bounds.
- CRect GetScheduledPaintRectConstrainedToSize();
+ RECT GetScheduledPaintRectConstrainedToSize();
// Tree functions
@@ -271,7 +271,7 @@ class RootView : public View,
Container* container_;
// The rectangle that should be painted
- CRect invalid_rect_;
+ gfx::Rect invalid_rect_;
// Whether the current invalid rect should be painted urgently.
bool invalid_rect_urgent_;
diff --git a/chrome/views/scroll_view.cc b/chrome/views/scroll_view.cc
index c6fdd7e..a440dd1 100644
--- a/chrome/views/scroll_view.cc
+++ b/chrome/views/scroll_view.cc
@@ -337,7 +337,7 @@ void ScrollView::ScrollToPosition(ScrollBar* source, int position) {
else if (position > max_pos)
position = max_pos;
contents_->SetX(-position);
- contents_->SchedulePaint(contents_->GetLocalBounds(true).ToRECT(), true);
+ contents_->SchedulePaint(contents_->GetLocalBounds(true), true);
}
} else if (source == vert_sb_ && vert_sb_->IsVisible()) {
int vh = viewport_->height();
@@ -350,7 +350,7 @@ void ScrollView::ScrollToPosition(ScrollBar* source, int position) {
else if (position > max_pos)
position = max_pos;
contents_->SetY(-position);
- contents_->SchedulePaint(contents_->GetLocalBounds(true).ToRECT(), true);
+ contents_->SchedulePaint(contents_->GetLocalBounds(true), true);
}
}
}
diff --git a/chrome/views/tooltip_manager.cc b/chrome/views/tooltip_manager.cc
index 6ddc31b..6da2245 100644
--- a/chrome/views/tooltip_manager.cc
+++ b/chrome/views/tooltip_manager.cc
@@ -190,7 +190,7 @@ LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) {
*handled = true;
tooltip_showing_ = true;
// The tooltip is about to show, allow the view to position it
- CPoint text_origin;
+ gfx::Point text_origin;
if (tooltip_height_ == 0)
tooltip_height_ = CalcTooltipHeight();
gfx::Point view_loc(last_mouse_x_, last_mouse_y_);
@@ -198,7 +198,7 @@ LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) {
last_tooltip_view_, &view_loc);
if (last_tooltip_view_->GetTooltipTextOrigin(
view_loc.x(), view_loc.y(), &text_origin) &&
- SetTooltipPosition(text_origin.x, text_origin.y)) {
+ SetTooltipPosition(text_origin.x(), text_origin.y())) {
// Return true, otherwise the rectangle we specified is ignored.
return TRUE;
}
diff --git a/chrome/views/view.cc b/chrome/views/view.cc
index 2b6c7cd..285aed7 100644
--- a/chrome/views/view.cc
+++ b/chrome/views/view.cc
@@ -159,9 +159,8 @@ gfx::Rect View::GetLocalBounds(bool include_border) const {
width() - insets.width(), height() - insets.height());
}
-void View::GetPosition(CPoint* p) const {
- p->x = GetX(APPLY_MIRRORING_TRANSFORMATION);
- p->y = y();
+gfx::Point View::GetPosition() const {
+ return gfx::Point(GetX(APPLY_MIRRORING_TRANSFORMATION), y());
}
gfx::Size View::GetPreferredSize() {
@@ -317,29 +316,25 @@ void View::SetHotTracked(bool flag) {
//
/////////////////////////////////////////////////////////////////////////////
-void View::SchedulePaint(const CRect& r, bool urgent) {
- if (!IsVisible()) {
+void View::SchedulePaint(const gfx::Rect& r, bool urgent) {
+ if (!IsVisible())
return;
- }
if (parent_) {
// Translate the requested paint rect to the parent's coordinate system
// then pass this notification up to the parent.
- CRect paint_rect(r);
- CPoint p;
- GetPosition(&p);
- paint_rect.OffsetRect(p);
+ gfx::Rect paint_rect = r;
+ paint_rect.Offset(GetPosition());
parent_->SchedulePaint(paint_rect, urgent);
}
}
void View::SchedulePaint() {
- SchedulePaint(GetLocalBounds(true).ToRECT(), false);
+ SchedulePaint(GetLocalBounds(true), false);
}
void View::SchedulePaint(int x, int y, int w, int h) {
- CRect r(x, y, x + w, y + h);
- SchedulePaint(&r, false);
+ SchedulePaint(gfx::Rect(x, y, w, h), false);
}
void View::Paint(ChromeCanvas* canvas) {
@@ -1506,7 +1501,7 @@ bool View::GetTooltipText(int x, int y, std::wstring* tooltip) {
return false;
}
-bool View::GetTooltipTextOrigin(int x, int y, CPoint* loc) {
+bool View::GetTooltipTextOrigin(int x, int y, gfx::Point* loc) {
return false;
}
diff --git a/chrome/views/view.h b/chrome/views/view.h
index b96e9ca..3df1c72 100644
--- a/chrome/views/view.h
+++ b/chrome/views/view.h
@@ -6,13 +6,9 @@
#define CHROME_VIEWS_VIEW_H_
#include <map>
+#include <oleacc.h>
#include <vector>
-// TODO(maruel): Remove these once WTL::CRect and WTL::CPoint are no more used.
-#include <atlbase.h>
-#include <atlapp.h>
-#include <atlmisc.h>
-
#include "base/gfx/rect.h"
#include "base/scoped_ptr.h"
#include "chrome/views/accelerator.h"
@@ -173,11 +169,12 @@ class View : public AcceleratorTarget {
// This is the function subclasses should use whenever they need to obtain
// the left position of one of their child views (for example, when
// implementing View::Layout()).
- int x() const {
- // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but
- // inlinable.
- return bounds_.x();
- };
+ // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but
+ // inlinable.
+ int x() const { return bounds_.x(); }
+ int y() const { return bounds_.y(); }
+ int width() const { return bounds_.width(); }
+ int height() const { return bounds_.height(); }
// Return the left coordinate of the View, relative to the parent. If
// |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of
@@ -191,16 +188,6 @@ class View : public AcceleratorTarget {
// coordinate of a child View.
int GetX(PositionMirroringSettings settings) const;
- int y() const {
- return bounds_.y();
- };
- int width() const {
- return bounds_.width();
- };
- int height() const {
- return bounds_.height();
- };
-
// Return this control local bounds. If include_border is true, local bounds
// is the rectangle {0, 0, width(), height()}, otherwise, it does not
// include the area where the border (if any) is painted.
@@ -211,7 +198,7 @@ class View : public AcceleratorTarget {
// Note that if the parent uses right-to-left UI layout, then the mirrored
// position of this View is returned. Use x()/y() if you want to ignore
// mirroring.
- void GetPosition(CPoint* out) const;
+ gfx::Point GetPosition() const;
// Get the size the View would like to be, if enough space were available.
virtual gfx::Size GetPreferredSize();
@@ -364,7 +351,7 @@ class View : public AcceleratorTarget {
// Mark the specified rectangle as dirty (needing repaint). If |urgent| is
// true, the view will be repainted when the current event processing is
// done. Otherwise, painting will take place as soon as possible.
- virtual void SchedulePaint(const CRect& r, bool urgent);
+ virtual void SchedulePaint(const gfx::Rect& r, bool urgent);
// Mark the entire View's bounds as dirty. Painting will occur as soon as
// possible.
@@ -909,7 +896,7 @@ class View : public AcceleratorTarget {
// Returns the location (relative to this View) for the text on the tooltip
// to display. If false is returned (the default), the tooltip is placed at
// a default position.
- virtual bool GetTooltipTextOrigin(int x, int y, CPoint* loc);
+ virtual bool GetTooltipTextOrigin(int x, int y, gfx::Point* loc);
// Set whether this view is owned by its parent. A view that is owned by its
// parent is automatically deleted when the parent is deleted. The default is
@@ -1045,10 +1032,6 @@ class View : public AcceleratorTarget {
// window associated with them (so the root view gets the keyboard messages).
virtual void Focus();
- // Heavyweight views (views that hold a native control) should return the
- // window for that control.
- virtual HWND GetNativeControlHWND() { return NULL; }
-
// Invoked when a key is pressed before the key event is processed by the
// focus manager for accelerators. This gives a chance to the view to
// override an accelerator. Subclasser should return false if they want to