diff options
-rw-r--r-- | ui/views/demo/main.cc | 16 | ||||
-rw-r--r-- | ui/views/events/event.cc | 2 | ||||
-rw-r--r-- | ui/views/events/event_win.cc | 52 | ||||
-rw-r--r-- | ui/views/focus/focus_manager.cc | 2 | ||||
-rw-r--r-- | ui/views/focus/focus_search.cc | 21 | ||||
-rw-r--r-- | ui/views/layout/fill_layout.cc | 10 | ||||
-rw-r--r-- | ui/views/rendering/border_unittest.cc | 2 | ||||
-rw-r--r-- | ui/views/view.cc | 397 | ||||
-rw-r--r-- | ui/views/view.h | 134 | ||||
-rw-r--r-- | ui/views/view_unittest.cc | 62 | ||||
-rw-r--r-- | ui/views/views.gyp | 2 | ||||
-rw-r--r-- | ui/views/widget/root_view_unittest.cc | 2 | ||||
-rw-r--r-- | ui/views/widget/widget.cc | 10 |
13 files changed, 344 insertions, 368 deletions
diff --git a/ui/views/demo/main.cc b/ui/views/demo/main.cc index eca756f..19dfc9d 100644 --- a/ui/views/demo/main.cc +++ b/ui/views/demo/main.cc @@ -88,8 +88,9 @@ class FancyPantsView : public ColorView { // Overridden from ui::View: virtual void Layout() { - c1_->SetBounds(20, 20, width() - 40, height() - 40); - c2_->SetBounds(50, 50, 50, 50); + c1_->SetBounds(gfx::Rect(20, 20, std::max(width() - 40, 0), + std::max(height() - 40, 0))); + c2_->SetBounds(gfx::Rect(50, 50, 50, 50)); Invalidate(); } virtual bool OnMousePressed(const ui::MouseEvent& event) { @@ -100,8 +101,8 @@ class FancyPantsView : public ColorView { } virtual bool OnMouseDragged(const ui::MouseEvent& event) { gfx::Rect old_bounds = bounds(); - SetPosition(gfx::Point(event.x() - mouse_offset_.x(), - event.y() - mouse_offset_.y())); + SetOrigin(gfx::Point(event.x() - mouse_offset_.x(), + event.y() - mouse_offset_.y())); gfx::Rect new_bounds = bounds(); parent()->InvalidateRect(old_bounds.Union(new_bounds)); return true; @@ -135,7 +136,7 @@ class ContentsView : public ColorView { set_parent_owned(false); AddChildView(c1_); AddChildView(c2_); - c3_->SetPosition(gfx::Point(200, 200)); + c3_->SetOrigin(gfx::Point(200, 200)); AddChildView(c3_); } @@ -148,8 +149,9 @@ class ContentsView : public ColorView { private: // Overridden from ui::View: virtual void Layout() { - c1_->SetBounds(20, 20, width() - 40, height() - 40); - c2_->SetBounds(50, 50, 50, 50); + c1_->SetBounds(gfx::Rect(20, 20, std::max(width() - 40, 0), + std::max(height() - 40, 0))); + c2_->SetBounds(gfx::Rect(50, 50, 50, 50)); c3_->SetSize(gfx::Size(75, 75)); Invalidate(); } diff --git a/ui/views/events/event.cc b/ui/views/events/event.cc index a6da13b..c4e7697 100644 --- a/ui/views/events/event.cc +++ b/ui/views/events/event.cc @@ -44,7 +44,7 @@ LocatedEvent::LocatedEvent(const LocatedEvent& other, View* target) : Event(other.type(), other.flags()) { location_ = other.location(); - View::ConvertPointToView(source, target, &location_); + View::ConvertPointToView(*source, *target, &location_); } //////////////////////////////////////////////////////////////////////////////// diff --git a/ui/views/events/event_win.cc b/ui/views/events/event_win.cc index 15d92009..b0eb456 100644 --- a/ui/views/events/event_win.cc +++ b/ui/views/events/event_win.cc @@ -19,30 +19,30 @@ namespace { int GetKeyStateFlags() { int flags = 0; if (GetKeyState(VK_MENU) & 0x80) - flags |= ui::EF_ALT_DOWN; + flags |= ui::Event::EF_ALT_DOWN; if (GetKeyState(VK_SHIFT) & 0x80) - flags |= ui::EF_SHIFT_DOWN; + flags |= ui::Event::EF_SHIFT_DOWN; if (GetKeyState(VK_CONTROL) & 0x80) - flags |= ui::EF_CONTROL_DOWN; + flags |= ui::Event::EF_CONTROL_DOWN; return flags; } // Convert windows message identifiers to Event types. -ui::EventType EventTypeFromNative(NativeEvent native_event) { +ui::Event::EventType EventTypeFromNative(NativeEvent native_event) { switch (native_event.message) { case WM_KEYDOWN: case WM_SYSKEYDOWN: - return ui::ET_KEY_PRESSED; + return ui::Event::ET_KEY_PRESSED; case WM_KEYUP: case WM_SYSKEYUP: - return ui::ET_KEY_RELEASED; + return ui::Event::ET_KEY_RELEASED; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_NCLBUTTONDOWN: case WM_NCMBUTTONDOWN: case WM_NCRBUTTONDOWN: case WM_RBUTTONDOWN: - return ui::ET_MOUSE_PRESSED; + return ui::Event::ET_MOUSE_PRESSED; case WM_LBUTTONDBLCLK: case WM_LBUTTONUP: case WM_MBUTTONDBLCLK: @@ -55,19 +55,19 @@ ui::EventType EventTypeFromNative(NativeEvent native_event) { case WM_NCRBUTTONUP: case WM_RBUTTONDBLCLK: case WM_RBUTTONUP: - return ui::ET_MOUSE_RELEASED; + return ui::Event::ET_MOUSE_RELEASED; case WM_MOUSEMOVE: case WM_NCMOUSEMOVE: - return ui::ET_MOUSE_MOVED; + return ui::Event::ET_MOUSE_MOVED; case WM_MOUSEWHEEL: - return ui::ET_MOUSEWHEEL; + return ui::Event::ET_MOUSEWHEEL; case WM_MOUSELEAVE: case WM_NCMOUSELEAVE: - return ui::ET_MOUSE_EXITED; + return ui::Event::ET_MOUSE_EXITED; default: NOTREACHED(); } - return ui::ET_UNKNOWN; + return ui::Event::ET_UNKNOWN; } bool IsClientMouseEvent(NativeEvent native_event) { @@ -102,7 +102,7 @@ int MouseEventFlagsFromNative(NativeEvent native_event) { // Check if the event occurred in the non-client area. if (IsNonClientMouseEvent(native_event)) - flags |= ui::EF_IS_NON_CLIENT; + flags |= ui::MouseEvent::EF_IS_NON_CLIENT; // Check for double click events. switch (native_event.message) { @@ -112,28 +112,28 @@ int MouseEventFlagsFromNative(NativeEvent native_event) { case WM_LBUTTONDBLCLK: case WM_MBUTTONDBLCLK: case WM_RBUTTONDBLCLK: - flags |= ui::EF_IS_DOUBLE_CLICK; + flags |= ui::MouseEvent::EF_IS_DOUBLE_CLICK; break; } // Check for pressed buttons. if (IsClientMouseEvent(native_event)) { if (native_event.wParam & MK_LBUTTON) - flags |= ui::EF_LEFT_BUTTON_DOWN; + flags |= ui::MouseEvent::EF_LEFT_BUTTON_DOWN; if (native_event.wParam & MK_MBUTTON) - flags |= ui::EF_MIDDLE_BUTTON_DOWN; + flags |= ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN; if (native_event.wParam & MK_RBUTTON) - flags |= ui::EF_RIGHT_BUTTON_DOWN; + flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN; } else if (IsNonClientMouseEvent(native_event)) { switch (native_event.message) { case WM_NCLBUTTONDOWN: - flags |= ui::EF_LEFT_BUTTON_DOWN; + flags |= ui::MouseEvent::EF_LEFT_BUTTON_DOWN; break; case WM_NCMBUTTONDOWN: - flags |= ui::EF_MIDDLE_BUTTON_DOWN; + flags |= ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN; break; case WM_NCRBUTTONDOWN: - flags |= ui::EF_RIGHT_BUTTON_DOWN; + flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN; break; } } @@ -146,17 +146,17 @@ int MouseWheelEventFlagsFromNative(NativeEvent native_event) { int native_flags = GET_KEYSTATE_WPARAM(native_event.wParam); int flags = 0; if (native_flags & MK_CONTROL) - flags |= ui::EF_CONTROL_DOWN; + flags |= ui::Event::EF_CONTROL_DOWN; if (native_flags & MK_SHIFT) - flags |= ui::EF_SHIFT_DOWN; + flags |= ui::Event::EF_SHIFT_DOWN; if (GetKeyState(VK_MENU) < 0) - flags |= ui::EF_ALT_DOWN; + flags |= ui::Event::EF_ALT_DOWN; if (native_flags & MK_LBUTTON) - flags |= ui::EF_LEFT_BUTTON_DOWN; + flags |= ui::Event::EF_LEFT_BUTTON_DOWN; if (native_flags & MK_MBUTTON) - flags |= ui::EF_MIDDLE_BUTTON_DOWN; + flags |= ui::Event::EF_MIDDLE_BUTTON_DOWN; if (native_flags & MK_RBUTTON) - flags |= ui::EF_RIGHT_BUTTON_DOWN; + flags |= ui::Event::EF_RIGHT_BUTTON_DOWN; return flags; } diff --git a/ui/views/focus/focus_manager.cc b/ui/views/focus/focus_manager.cc index 20baabe..fa2b8f2 100644 --- a/ui/views/focus/focus_manager.cc +++ b/ui/views/focus/focus_manager.cc @@ -143,7 +143,7 @@ bool FocusManager::OnKeyEvent(const KeyEvent& event) { key_code == ui::VKEY_LEFT || key_code == ui::VKEY_RIGHT)) { bool next = (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN); std::vector<View*> views; - focused_view_->parent()->GetViewsWithGroup(focused_view_->group(), &views); + focused_view_->parent()->GetViewsInGroup(focused_view_->group(), &views); std::vector<View*>::const_iterator iter = std::find(views.begin(), views.end(), focused_view_); diff --git a/ui/views/focus/focus_search.cc b/ui/views/focus/focus_search.cc index c8093fd0..083fc7c 100644 --- a/ui/views/focus/focus_search.cc +++ b/ui/views/focus/focus_search.cc @@ -24,7 +24,7 @@ View* FocusSearch::FindNextFocusableView(View* starting_view, *focus_traversable = NULL; *focus_traversable_view = NULL; - if (root_->child_count() == 0) { + if (root_->children_empty()) { NOTREACHED(); // Nothing to focus on here. return NULL; @@ -39,14 +39,14 @@ View* FocusSearch::FindNextFocusableView(View* starting_view, // Default to the first/last child starting_view = reverse ? - root_->GetChildViewAt(root_->child_count() - 1) : - root_->GetChildViewAt(0); + root_->child_at(root_->children_size() - 1) : + root_->child_at(0); // If there was no starting view, then the one we select is a potential // focus candidate. check_starting_view = true; } else { // The starting view should be a direct or indirect child of the root. - DCHECK(root_->Contains(starting_view)); + DCHECK(root_->Contains(*starting_view)); } View* v = NULL; @@ -70,7 +70,7 @@ View* FocusSearch::FindNextFocusableView(View* starting_view, } // Don't set the focus to something outside of this view hierarchy. - if (v && v != root_ && !root_->Contains(v)) + if (v && v != root_ && !root_->Contains(*v)) v = NULL; // If |cycle_| is true, prefer to keep cycling rather than returning NULL. @@ -121,7 +121,7 @@ View* FocusSearch::FindSelectedViewForGroup(View* view) const { } View* FocusSearch::GetParent(View* v) const { - return root_->Contains(v) ? v->parent() : NULL; + return root_->Contains(*v) ? v->parent() : NULL; } // Strategy for finding the next focusable view: @@ -158,8 +158,8 @@ View* FocusSearch::FindNextFocusableViewImpl( // First let's try the left child. if (can_go_down) { - if (starting_view->child_count() > 0) { - View* v = FindNextFocusableViewImpl(starting_view->GetChildViewAt(0), + if (!starting_view->children_empty()) { + View* v = FindNextFocusableViewImpl(starting_view->child_at(0), true, false, true, skip_group_id, focus_traversable, focus_traversable_view); @@ -223,9 +223,8 @@ View* FocusSearch::FindPreviousFocusableViewImpl( return NULL; } - if (starting_view->child_count() > 0) { - View* view = - starting_view->GetChildViewAt(starting_view->child_count() - 1); + if (!starting_view->children_empty()) { + View* view = starting_view->child_at(starting_view->children_size() - 1); View* v = FindPreviousFocusableViewImpl(view, true, false, true, skip_group_id, focus_traversable, diff --git a/ui/views/layout/fill_layout.cc b/ui/views/layout/fill_layout.cc index 5c603c7..2c5e588 100644 --- a/ui/views/layout/fill_layout.cc +++ b/ui/views/layout/fill_layout.cc @@ -22,16 +22,16 @@ FillLayout::~FillLayout() { // FillLayout, LayoutManager implementation: void FillLayout::Layout(View* host) { - if (host->child_count() == 0) + if (host->children_empty()) return; - View* child = host->GetChildViewAt(0); - child->SetBounds(0, 0, host->width(), host->height()); + View* child = host->child_at(0); + child->SetBounds(gfx::Rect(gfx::Point(), host->size())); } gfx::Size FillLayout::GetPreferredSize(View* host) { - DCHECK(host->child_count() == 1); - return host->GetChildViewAt(0)->GetPreferredSize(); + DCHECK_EQ(1U, host->children_size()); + return host->child_at(0)->GetPreferredSize(); } } // namespace ui diff --git a/ui/views/rendering/border_unittest.cc b/ui/views/rendering/border_unittest.cc index 2b7740d..baa585c 100644 --- a/ui/views/rendering/border_unittest.cc +++ b/ui/views/rendering/border_unittest.cc @@ -53,7 +53,7 @@ class PaintableView : public View { TEST_F(BorderTest, Basic) { const int kViewSize = 100; PaintableView v; - v.SetBounds(10, 10, kViewSize, kViewSize); + v.SetBounds(gfx::Rect(10, 10, kViewSize, kViewSize)); // With no border, the content size is the view size. EXPECT_EQ(gfx::Rect(0, 0, kViewSize, kViewSize), v.GetContentsBounds()); diff --git a/ui/views/view.cc b/ui/views/view.cc index ac4bd11..5742af1 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -64,23 +64,30 @@ View::View() View::~View() { if (parent_) - parent_->RemoveChildView(this); + parent_->RemoveChildView(this, false); - ViewVector::const_iterator it = children_.begin(); - for (; it != children_.end(); ++it) { - (*it)->parent_ = NULL; - if ((*it)->parent_owned()) - delete *it; + for (Views::const_iterator i(children_begin()); i != children_.end(); ++i) { + (*i)->parent_ = NULL; + if ((*i)->parent_owned()) + delete *i; } } // Size and disposition -------------------------------------------------------- -void View::SetBounds(int x, int y, int width, int height) { - SetBoundsRect(gfx::Rect(x, y, std::max(0, width), std::max(0, height))); +gfx::Rect View::GetVisibleBounds() const { + // TODO(beng): + return bounds(); +} + +gfx::Rect View::GetContentsBounds() const { + gfx::Rect rect(gfx::Point(), size()); + if (border_.get()) + rect.Inset(border_->insets()); + return rect; } -void View::SetBoundsRect(const gfx::Rect& bounds) { +void View::SetBounds(const gfx::Rect& bounds) { gfx::Rect old_bounds = bounds_; bounds_ = bounds; // TODO(beng): investigate usage of needs_layout_ in old View code. @@ -90,33 +97,18 @@ void View::SetBoundsRect(const gfx::Rect& bounds) { } } -gfx::Rect View::GetVisibleBounds() const { - // TODO(beng): - return bounds(); +void View::SetOrigin(const gfx::Point& origin) { + SetBounds(gfx::Rect(origin, size())); } void View::SetSize(const gfx::Size& size) { - SetBounds(x(), y(), size.width(), size.height()); -} - -void View::SetPosition(const gfx::Point& position) { - SetBounds(position.x(), position.y(), width(), height()); + SetBounds(gfx::Rect(origin(), size)); } void View::SetBorder(Border* border) { border_.reset(border); } -gfx::Rect View::GetContentsBounds() const { - if (border_.get()) { - return gfx::Rect( - border_->insets().left(), border_->insets().top(), - width() - border_->insets().right() - border_->insets().left(), - height() - border_->insets().bottom() - border_->insets().top()); - } - return gfx::Rect(0, 0, width(), height()); -} - void View::OnBoundsChanged() { } @@ -133,14 +125,12 @@ void View::SetLayoutManager(LayoutManager* layout_manager) { } void View::Layout() { + // The layout manager handles all child layout if present. if (layout_manager_.get()) { - // Layout Manager handles laying out children. layout_manager_->Layout(this); } else { - // We handle laying out our own children. - ViewVector::iterator it = children_.begin(); - for (; it != children_.end(); ++it) - (*it)->Layout(); + std::for_each(children_begin(), children_end(), + std::mem_fun(&View::Layout)); } // TODO(beng): needs_layout_? SchedulePaint()? } @@ -148,7 +138,6 @@ void View::Layout() { void View::SetVisible(bool visible) { if (visible != visible_) { visible_ = visible; - // InvaldateRect() checks for view visibility before proceeding, so we need // to ask the parent to invalidate our bounds. if (parent_) @@ -165,24 +154,22 @@ void View::SetEnabled(bool enabled) { // Attributes ------------------------------------------------------------------ -View* View::GetViewById(int id) const { +View* View::GetViewByID(int id) { if (id_ == id) - return const_cast<View*>(this); - ViewVector::const_iterator it = children_.begin(); - for (; it != children_.end(); ++it) { - View* view = (*it)->GetViewById(id); + return this; + for (Views::const_iterator i(children_begin()); i != children_end(); ++i) { + View* view = (*i)->GetViewByID(id); if (view) return view; } return NULL; } -void View::GetViewsWithGroup(int group, ViewVector* vec) const { +void View::GetViewsInGroup(int group, Views* vec) { if (group_ == group) vec->push_back(const_cast<View*>(this)); - ViewVector::const_iterator it = children_.begin(); - for (; it != children_.end(); ++it) - (*it)->GetViewsWithGroup(group, vec); + for (Views::const_iterator i(children_begin()); i != children_end(); ++i) + (*i)->GetViewsInGroup(group, vec); } View* View::GetSelectedViewForGroup(int group_id) { @@ -193,64 +180,63 @@ View* View::GetSelectedViewForGroup(int group_id) { // Coordinate conversion ------------------------------------------------------- // static -void View::ConvertPointToView(View* source, View* target, gfx::Point* point) { - View* inner = NULL; - View* outer = NULL; - if (source->Contains(target)) { - inner = target; - outer = source; - } else if (target->Contains(source)) { - inner = source; - outer = target; - } // Note that we cannot do a plain "else" here since |source| and |target| - // may be in different hierarchies with no relation. - - if (inner && outer) { - gfx::Point offset; - View* temp = inner; - while (temp != outer) { - offset.Offset(temp->x(), temp->y()); - temp = temp->parent(); - } - // When target is contained by source, we need to subtract the offset. - // When source is contained by target, we need to add the fofset. - int multiplier = inner == target ? -1 : 1; - point->Offset(multiplier * offset.x(), multiplier * offset.y()); - } +void View::ConvertPointToView(const View& source, + const View& target, + gfx::Point* point) { + const View* inner = NULL; + const View* outer = NULL; + if (source.Contains(target)) { + inner = ⌖ + outer = &source; + } else if (target.Contains(source)) { + inner = &source; + outer = ⌖ + } // Note that we cannot do a plain "else" here since |source| and |target| + // may be in different hierarchies with no relation. + if (!inner) + return; + + gfx::Point offset; + for (const View* v = inner; v != outer; v = v->parent()) + offset.Offset(v->x(), v->y()); + // When target is contained by source, we need to subtract the offset. + // When source is contained by target, we need to add the offset. + int multiplier = (inner == &target) ? -1 : 1; + point->Offset(multiplier * offset.x(), multiplier * offset.y()); } // static -void View::ConvertPointToScreen(View* source, gfx::Point* point) { - Widget* widget = source->GetWidget(); +void View::ConvertPointToScreen(const View& source, gfx::Point* point) { + const Widget* widget = source.GetWidget(); if (widget) { ConvertPointToWidget(source, point); - gfx::Rect r = widget->GetClientAreaScreenBounds(); - point->Offset(r.x(), r.y()); + gfx::Point client_origin(widget->GetClientAreaScreenBounds().origin()); + point->Offset(client_origin.x(), client_origin.y()); } } // static -void View::ConvertPointToWidget(View* source, gfx::Point* point) { - for (View* v = source; v; v = v->parent()) +void View::ConvertPointToWidget(const View& source, gfx::Point* point) { + for (const View* v = &source; v; v = v->parent()) point->Offset(v->x(), v->y()); } // Tree operations ------------------------------------------------------------- -Widget* View::GetWidget() const { - return parent_ ? parent_->GetWidget() : NULL; +const Widget* View::GetWidget() const { + return parent() ? parent()->GetWidget() : NULL; } void View::AddChildView(View* view) { - AddChildViewAt(view, children_.size()); + AddChildViewAt(view, children_size()); } void View::AddChildViewAt(View* view, size_t index) { - CHECK(view != this) << "A view cannot be its own child."; + CHECK_NE(this, view) << "A view cannot be its own child."; // Remove the child from its current parent if any. if (view->parent()) - view->parent()->RemoveChildView(view); + view->parent()->RemoveChildView(view, false); // TODO(beng): Move focus initialization to FocusManager. InitFocusSiblings(view, index); @@ -259,48 +245,36 @@ void View::AddChildViewAt(View* view, size_t index) { view->parent_ = this; // Notify the hierarchy. - NotifyHierarchyChanged(this, view, true); + NotifyHierarchyChanged(view, true); // TODO(beng): Notify other objects like tooltip, layout manager, etc. // Figure out RegisterChildrenForVisibleBoundsNotification. } -View* View::RemoveChildView(View* view) { - ViewVector::iterator it = find(children_.begin(), children_.end(), view); - if (it != children_.end()) { - View* old_parent = view->parent_; - view->parent_ = NULL; - children_.erase(it); - NotifyHierarchyChanged(old_parent, view, false); - } - +void View::RemoveChildView(View* view, bool delete_child) { + Views::const_iterator i(std::find(children_begin(), children_end(), view)); + DCHECK(i != children_end()); + view->parent_ = NULL; + children_.erase(i); + NotifyHierarchyChanged(view, false); // TODO(beng): Notify other objects like tooltip, layout manager, etc. - return view; + if (delete_child) + delete view; } void View::RemoveAllChildViews(bool delete_children) { - // TODO(beng): use for_each. - ViewVector::iterator it = children_.begin(); - while (it != children_.end()) { - View* v = RemoveChildView(*it); - if (delete_children) - delete v; + while (!children_.empty()) { + RemoveChildView(children_.front(), delete_children); // TODO(beng): view deletion is actually more complicated in the old view.cc // figure out why. (it uses a ScopedVector to accumulate a list // of views to delete). } } -View* View::GetChildViewAt(size_t index) { - CHECK(index < child_count()); - return children_[index]; -} - -bool View::Contains(View* child) { - while (child) { - if (child == this) +bool View::Contains(const View& child) const { + for (const View* v = &child; v; v = v->parent()) { + if (v == this) return true; - child = child->parent(); } return false; } @@ -308,15 +282,12 @@ bool View::Contains(View* child) { // Painting -------------------------------------------------------------------- void View::Invalidate() { - InvalidateRect(gfx::Rect(0, 0, width(), height())); + InvalidateRect(gfx::Rect(gfx::Point(), size())); } void View::InvalidateRect(const gfx::Rect& invalid_rect) { - if (!visible_) - return; - - if (parent_) { - gfx::Rect r = invalid_rect; + if (visible_ && parent_) { + gfx::Rect r(invalid_rect); r.Offset(bounds_.origin()); parent_->InvalidateRect(r); } @@ -326,7 +297,7 @@ void View::InvalidateRect(const gfx::Rect& invalid_rect) { bool View::HitTest(const gfx::Point& point) const { // TODO(beng): Hit test mask support. - return gfx::Rect(0, 0, width(), height()).Contains(point); + return gfx::Rect(gfx::Point(), size()).Contains(point); } // Accelerators ---------------------------------------------------------------- @@ -342,20 +313,25 @@ void View::RemoveAllAccelerators() { // Focus ----------------------------------------------------------------------- -FocusManager* View::GetFocusManager() const { - Widget* widget = GetWidget(); +FocusManager* View::GetFocusManager() { + return const_cast<FocusManager*>(static_cast<const View*>(this)-> + GetFocusManager()); +} + +const FocusManager* View::GetFocusManager() const { + const Widget* widget = GetWidget(); return widget ? widget->GetFocusManager() : NULL; } -FocusTraversable* View::GetFocusTraversable() const { +FocusTraversable* View::GetFocusTraversable() { return NULL; } -View* View::GetNextFocusableView() const { +View* View::GetNextFocusableView() { return NULL; } -View* View::GetPreviousFocusableView() const { +View* View::GetPreviousFocusableView() { return NULL; } @@ -364,19 +340,19 @@ bool View::IsFocusable() const { } bool View::HasFocus() const { - FocusManager* focus_manager = GetFocusManager(); - return focus_manager ? focus_manager->focused_view() == this : false; + const FocusManager* focus_manager = GetFocusManager(); + return focus_manager ? (focus_manager->focused_view() == this) : false; } void View::RequestFocus() { FocusManager* focus_manager = GetFocusManager(); - if (focus_manager && focus_manager->focused_view() != this) + if (focus_manager && (focus_manager->focused_view() != this)) focus_manager->SetFocusedView(this); } // Resources ------------------------------------------------------------------- -ThemeProvider* View::GetThemeProvider() const { +ThemeProvider* View::GetThemeProvider() { Widget* widget = GetWidget(); return widget ? widget->GetThemeProvider() : NULL; } @@ -386,10 +362,10 @@ ThemeProvider* View::GetThemeProvider() const { // Tree operations ------------------------------------------------------------- -void View::OnViewAdded(View* parent, View* child) { +void View::OnViewAdded(const View& parent, const View& child) { } -void View::OnViewRemoved(View* parent, View* child) { +void View::OnViewRemoved(const View& parent, const View& child) { } void View::OnViewAddedToWidget() { @@ -401,12 +377,8 @@ void View::OnViewRemovedFromWidget() { // Painting -------------------------------------------------------------------- void View::PaintChildren(gfx::Canvas* canvas) { - // TODO(beng): use for_each. - // std::for_each(children_.begin(), children_.end(), - // std::bind2nd(std::mem_fun_ref(&View::Paint), canvas)); - ViewVector::iterator it = children_.begin(); - for (; it != children_.end(); ++it) - (*it)->Paint(canvas); + std::for_each(children_begin(), children_end(), + std::bind2nd(std::mem_fun(&View::Paint), canvas)); } void View::OnPaint(gfx::Canvas* canvas) { @@ -421,7 +393,7 @@ void View::OnPaintBackground(gfx::Canvas* canvas) { void View::OnPaintBorder(gfx::Canvas* canvas) { if (border_.get()) - border_->Paint(const_cast<const View*>(this), canvas); + border_->Paint(this, canvas); } void View::OnPaintFocusBorder(gfx::Canvas* canvas) { @@ -429,23 +401,21 @@ void View::OnPaintFocusBorder(gfx::Canvas* canvas) { // Input ----------------------------------------------------------------------- -View* View::GetEventHandlerForPoint(const gfx::Point& point) const { - ViewVector::const_reverse_iterator it = children_.rbegin(); - for (; it != children_.rend(); ++it) { - View* child = *it; - if (!child->visible()) - continue; - - gfx::Point point_in_child_coords(point); - View::ConvertPointToView(const_cast<View*>(this), child, - &point_in_child_coords); - if (child->HitTest(point_in_child_coords)) - return child->GetEventHandlerForPoint(point_in_child_coords); +View* View::GetEventHandlerForPoint(const gfx::Point& point) { + for (Views::const_reverse_iterator i(children_rbegin()); i != children_rend(); + ++i) { + View* child = *i; + if (child->visible()) { + gfx::Point point_in_child_coords(point); + View::ConvertPointToView(*this, *child, &point_in_child_coords); + if (child->HitTest(point_in_child_coords)) + return child->GetEventHandlerForPoint(point_in_child_coords); + } } - return const_cast<View*>(this); + return this; } -gfx::NativeCursor View::GetCursorForPoint(const gfx::Point& point) { +gfx::NativeCursor View::GetCursorForPoint(const gfx::Point& point) const { return NULL; } @@ -515,7 +485,7 @@ bool View::IsAccessibilityFocusableInRootView() const { return false; } -FocusTraversable* View::GetPaneFocusTraversable() const { +FocusTraversable* View::GetPaneFocusTraversable() { // TODO(beng): figure out what to do about this. return NULL; } @@ -541,55 +511,39 @@ void View::DragInfo::PossibleDrag(const gfx::Point& point) { // Tree operations ------------------------------------------------------------- -void View::NotifyHierarchyChanged(View* parent, View* child, bool is_add) { - // Notify the child. Note that we call GetWidget() on the parent, not the - // child, since this method is called after the child is already removed from - // the hierarchy when |is_add| is false and so child->GetWidget() will always - // return NULL. - bool has_widget = parent->GetWidget() != NULL; - CallViewNotification(child, parent, child, is_add, has_widget); - +void View::NotifyHierarchyChanged(View* child, bool is_add) { // Notify the hierarchy up. - NotifyHierarchyChangedUp(parent, child, is_add); + for (View* v = parent(); v; v = v->parent()) + CallViewNotification(v, *child, is_add, false); // Notify the hierarchy down. + bool has_widget = GetWidget() != NULL; if (!is_add) { // Because |child| has already been removed from |parent|'s child list, we // need to notify its hierarchy manually. - child->NotifyHierarchyChangedDown(parent, child, is_add, has_widget); + child->NotifyHierarchyChangedDown(*child, is_add, has_widget); } - NotifyHierarchyChangedDown(parent, child, is_add, has_widget); + NotifyHierarchyChangedDown(*child, is_add, has_widget); } -void View::NotifyHierarchyChangedUp(View* parent, View* child, bool is_add) { - for (View* v = parent; v; v = v->parent()) { - if (is_add) - v->OnViewAdded(parent, child); - else - v->OnViewRemoved(parent, child); - } -} - -void View::NotifyHierarchyChangedDown(View* parent, View* child, bool is_add, - bool has_widget) { - ViewVector::iterator it = children_.begin(); - for (; it != children_.end(); ++it) { - CallViewNotification(*it, parent, child, is_add, has_widget); - (*it)->NotifyHierarchyChangedDown(parent, child, is_add, has_widget); - } +void View::NotifyHierarchyChangedDown(const View& child, + bool is_add, + bool has_widget) { + CallViewNotification(this, child, is_add, has_widget); + for (Views::const_iterator i(children_begin()); i != children_end(); ++i) + (*i)->NotifyHierarchyChangedDown(child, is_add, has_widget); } void View::CallViewNotification(View* target, - View* parent, - View* child, + const View& child, bool is_add, bool has_widget) { if (is_add) { - target->OnViewAdded(parent, child); + target->OnViewAdded(*this, child); if (has_widget) target->OnViewAddedToWidget(); } else { - target->OnViewRemoved(parent, child); + target->OnViewRemoved(*this, child); if (has_widget) target->OnViewRemovedFromWidget(); } @@ -620,16 +574,12 @@ bool View::MousePressed(const MouseEvent& event, DragInfo* drag_info) { if (!enabled_) return handled; - int drag_operations = - enabled_ && event.IsOnlyLeftMouseButton() && HitTest(event.location()) ? - GetDragOperations(event.location()) : DragDropTypes::DRAG_NONE; - if (drag_operations != DragDropTypes::DRAG_NONE) { - drag_info->PossibleDrag(event.location()); - return true; - } - bool has_context_menu = event.IsRightMouseButton() ? - !!context_menu_controller_ : NULL; - return has_context_menu || handled; + if (!event.IsOnlyLeftMouseButton() || !HitTest(event.location()) || + (GetDragOperations(event.location()) == DragDropTypes::DRAG_NONE)) + return handled || (event.IsRightMouseButton() && context_menu_controller_); + + drag_info->PossibleDrag(event.location()); + return true; } bool View::MouseDragged(const MouseEvent& event, DragInfo* drag_info) { @@ -637,15 +587,13 @@ bool View::MouseDragged(const MouseEvent& event, DragInfo* drag_info) { ExceededDragThreshold(drag_info->press_point, event.location())) { if (!drag_controller_ || drag_controller_->CanStartDrag(this, drag_info->press_point, - event.location())) { + event.location())) StartShellDrag(event, drag_info->press_point); - } - } else { - if (OnMouseDragged(event)) - return true; + } else if (OnMouseDragged(event)) { + return true; } // TODO(beng): Handle view deletion from OnMouseDragged(). - return !!context_menu_controller_ || drag_info->possible_drag; + return context_menu_controller_ || drag_info->possible_drag; } void View::MouseReleased(const MouseEvent& event) { @@ -654,7 +602,7 @@ void View::MouseReleased(const MouseEvent& event) { if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { gfx::Point location(event.location()); if (HitTest(location)) { - ConvertPointToScreen(this, &location); + ConvertPointToScreen(*this, &location); context_menu_controller_->ShowContextMenu(this, location, true); } } @@ -664,51 +612,48 @@ void View::MouseReleased(const MouseEvent& event) { // TODO(beng): Move to FocusManager. void View::InitFocusSiblings(View* view, size_t index) { - if (child_count() == 0) { + if (children_empty()) { view->next_focusable_view_ = NULL; view->prev_focusable_view_ = NULL; - } else { - if (index == child_count()) { - // We are inserting at the end, but the end of the child list may not be - // the last focusable element. Let's try to find an element with no next - // focusable element to link to. - View* last_focusable_view = NULL; - for (std::vector<View*>::iterator iter = children_.begin(); - iter != children_.end(); ++iter) { - if (!(*iter)->next_focusable_view_) { - last_focusable_view = *iter; - break; - } - } - if (last_focusable_view == NULL) { - // Hum... there is a cycle in the focus list. Let's just insert ourself - // after the last child. - View* prev = children_[index - 1]; - view->prev_focusable_view_ = prev; - view->next_focusable_view_ = prev->next_focusable_view_; - prev->next_focusable_view_->prev_focusable_view_ = view; - prev->next_focusable_view_ = view; - } else { - last_focusable_view->next_focusable_view_ = view; - view->next_focusable_view_ = NULL; - view->prev_focusable_view_ = last_focusable_view; - } - } else { - View* prev = children_[index]->GetPreviousFocusableView(); - view->prev_focusable_view_ = prev; - view->next_focusable_view_ = children_[index]; - if (prev) - prev->next_focusable_view_ = view; - children_[index]->prev_focusable_view_ = view; + return; + } + + if (index != children_size()) { + View* prev = children_[index]->GetPreviousFocusableView(); + view->prev_focusable_view_ = prev; + view->next_focusable_view_ = children_[index]; + if (prev) + prev->next_focusable_view_ = view; + children_[index]->prev_focusable_view_ = view; + return; + } + + // We are inserting at the end, but the end of the child list may not be + // the last focusable element. Let's try to find an element with no next + // focusable element to link to. + for (Views::const_iterator i(children_begin()); i != children_end(); ++i) { + if (!(*i)->next_focusable_view_) { + (*i)->next_focusable_view_ = view; + view->next_focusable_view_ = NULL; + view->prev_focusable_view_ = *i; + return; } } + + // Hum... there is a cycle in the focus list. Let's just insert ourself + // after the last child. + View* prev = children_[index - 1]; + view->prev_focusable_view_ = prev; + view->next_focusable_view_ = prev->next_focusable_view_; + prev->next_focusable_view_->prev_focusable_view_ = view; + prev->next_focusable_view_ = view; } // Drag & Drop ----------------------------------------------------------------- int View::GetDragOperations(const gfx::Point& point) { return drag_controller_ ? - drag_controller_->GetDragOperations(const_cast<View*>(this), point) : + drag_controller_->GetDragOperations(this, point) : DragDropTypes::DRAG_NONE; } diff --git a/ui/views/view.h b/ui/views/view.h index e3940fc..8067c32 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -39,7 +39,7 @@ class ThemeProvider; class Widget; //////////////////////////////////////////////////////////////////////////////// -// View class +// View // // View encapsulates rendering, layout and event handling for rectangles within // a view hierarchy. @@ -54,9 +54,10 @@ class Widget; // TODO(beng): consider the visibility of many of these methods. // consider making RootView a friend and making many private or // protected. + class View { public: - typedef std::vector<View*> ViewVector; + typedef std::vector<View*> Views; // Creation and lifetime ----------------------------------------------------- View(); @@ -72,24 +73,28 @@ class View { // Size and disposition ------------------------------------------------------ - void SetBounds(int x, int y, int width, int height); - void SetBoundsRect(const gfx::Rect& bounds); - void SetSize(const gfx::Size& size); - void SetPosition(const gfx::Point& position); gfx::Rect bounds() const { return bounds_; } + // Returns the portion of this view's bounds that are visible (i.e. not + // clipped) in the RootView. gfx::Rect GetVisibleBounds() const; - int x() const { return bounds_.x(); } - int y() const { return bounds_.y(); } - int width() const { return bounds_.width(); } - int height() const { return bounds_.height(); } - - // Owned by the view. - void SetBorder(Border* border); - Border* border() { return border_.get(); } - // Returns the bounds of the content area of the view, i.e. the rectangle // enclosed by the view's border. gfx::Rect GetContentsBounds() const; + void SetBounds(const gfx::Rect& bounds); + + gfx::Point origin() const { return bounds().origin(); } + int x() const { return bounds().x(); } + int y() const { return bounds().y(); } + void SetOrigin(const gfx::Point& origin); + + gfx::Size size() const { return bounds().size(); } + int width() const { return bounds().width(); } + int height() const { return bounds().height(); } + void SetSize(const gfx::Size& size); + + // Owned by the view. + Border* border() { return border_.get(); } + void SetBorder(Border* border); // Override to be notified when the bounds of a view have changed. virtual void OnBoundsChanged(); @@ -118,11 +123,11 @@ class View { // Returns the View within this View's hierarchy whose id matches that // specified. - View* GetViewById(int id) const; + View* GetViewByID(int id); - // Populates a ViewVector with the Views within this View's hierarchy that - // match the specified group id. - void GetViewsWithGroup(int group, ViewVector* vec) const; + // Populates |vec| with the Views within this View's hierarchy that match the + // specified group id. + void GetViewsInGroup(int group, Views* vec); // TODO(beng): implementme virtual View* GetSelectedViewForGroup(int group_id); @@ -130,46 +135,58 @@ class View { // Coordinate conversion ----------------------------------------------------- // Converts a point from the coordinate system of |source| to |target|. - static void ConvertPointToView(View* source, View* target, gfx::Point* point); + static void ConvertPointToView(const View& source, + const View& target, + gfx::Point* point); // Converts a point from the coordinate system of |source| to the screen. // If |source| is not attached to a Widget that is in screen space, |point| is // not modified. - static void ConvertPointToScreen(View* source, gfx::Point* point); + static void ConvertPointToScreen(const View& source, gfx::Point* point); // Converts a point from the coordinate system of |source| to the Widget that // most closely contains it. - static void ConvertPointToWidget(View* source, gfx::Point* point); + static void ConvertPointToWidget(const View& source, gfx::Point* point); // Tree operations ----------------------------------------------------------- // Returns the Widget that contains this View, or NULL if it is not contained // within a Widget. - virtual Widget* GetWidget() const; + Widget* GetWidget() { + return const_cast<Widget*>(static_cast<const View*>(this)->GetWidget()); + } + virtual const Widget* GetWidget() const; // Adds a View as a child of this one, optionally at |index|. void AddChildView(View* view); void AddChildViewAt(View* view, size_t index); - // Removes a View as a child of this View. Does not delete the child. - View* RemoveChildView(View* view); + // If |view| is a child of this View, removes it and optionally deletes it. + void RemoveChildView(View* view, bool delete_child); // Removes all View children of this View. Deletes the children if // |delete_children| is true. void RemoveAllChildViews(bool delete_children); - // Returns the View at the specified |index|. - View* GetChildViewAt(size_t index); - - // Returns the number of child views. - size_t child_count() const { return children_.size(); } + // STL-style accessors. + Views::const_iterator children_begin() { return children_.begin(); } + Views::const_iterator children_end() { return children_.end(); } + Views::const_reverse_iterator children_rbegin() { return children_.rbegin(); } + Views::const_reverse_iterator children_rend() { return children_.rend(); } + size_t children_size() const { return children_.size(); } + bool children_empty() const { return children_.empty(); } + View* child_at(size_t index) { + DCHECK_LT(index, children_size()); + return children_[index]; + } // Returns the parent View, or NULL if this View has no parent. - View* parent() const { return parent_; } + View* parent() { return parent_; } + const View* parent() const { return parent_; } // Returns true if |child| is contained within this View's hierarchy, even as // an indirect descendant. Will return true if child is also this View. - bool Contains(View* child); + bool Contains(const View& child) const; // Painting ------------------------------------------------------------------ @@ -195,16 +212,17 @@ class View { // Focus --------------------------------------------------------------------- // Manager. - FocusManager* GetFocusManager() const; + FocusManager* GetFocusManager(); + const FocusManager* GetFocusManager() const; // Traversal. - virtual FocusTraversable* GetFocusTraversable() const; - View* GetNextFocusableView() const; - View* GetPreviousFocusableView() const; + virtual FocusTraversable* GetFocusTraversable(); + View* GetNextFocusableView(); + View* GetPreviousFocusableView(); // Attributes. - void set_focusable(bool focusable) { focusable_ = focusable; } bool IsFocusable() const; + void set_focusable(bool focusable) { focusable_ = focusable; } bool HasFocus() const; void RequestFocus(); @@ -218,16 +236,18 @@ class View { // Resources ----------------------------------------------------------------- - ThemeProvider* GetThemeProvider() const; + ThemeProvider* GetThemeProvider(); protected: // Tree operations ----------------------------------------------------------- - // Called on every view in the hierarchy when a view is added or removed. - virtual void OnViewAdded(View* parent, View* child); - virtual void OnViewRemoved(View* parent, View* child); + // Called on every view in |parent|'s and |child|'s hierarchies, as well as + // ancestors, when |child| is added to or removed from |parent|. + virtual void OnViewAdded(const View& parent, const View& child); + virtual void OnViewRemoved(const View& parent, const View& child); - // Called on a View when it is added or removed from a Widget. + // Called on a View when it is part of a hierarchy that has been added to or + // removed from a Widget. virtual void OnViewAddedToWidget(); virtual void OnViewRemovedFromWidget(); @@ -262,9 +282,9 @@ class View { // locate views for event targeting. Override this function if you wish to // specify a view other than the one most closely enclosing |point| to receive // notifications for events within it. - virtual View* GetEventHandlerForPoint(const gfx::Point& point) const; + virtual View* GetEventHandlerForPoint(const gfx::Point& point); - virtual gfx::NativeCursor GetCursorForPoint(const gfx::Point& point); + virtual gfx::NativeCursor GetCursorForPoint(const gfx::Point& point) const; virtual bool OnKeyPressed(const KeyEvent& event); virtual bool OnKeyReleased(const KeyEvent& event); @@ -290,7 +310,7 @@ class View { // TODO(beng): kill these, move to focus manager. virtual bool IsFocusableInRootView() const; virtual bool IsAccessibilityFocusableInRootView() const; - virtual FocusTraversable* GetPaneFocusTraversable() const; + virtual FocusTraversable* GetPaneFocusTraversable(); virtual void OnFocus(const FocusEvent& event); virtual void OnBlur(const FocusEvent& event); @@ -320,13 +340,21 @@ class View { }; // Tree operations ----------------------------------------------------------- - void NotifyHierarchyChanged(View* parent, View* child, bool is_add); - void NotifyHierarchyChangedUp(View* parent, View* child, bool is_add); - void NotifyHierarchyChangedDown(View* parent, View* child, bool is_add, + + // Notifies all views in our and |child|'s hierarchies, as well as ancestors, + // that |child| was added to or removed from |this|. + void NotifyHierarchyChanged(View* child, bool is_add); + + // Notifies all views in our hierarchy that |child| was added to or removed + // from |this|. |has_widget| is true iff |this| is in a widget. + void NotifyHierarchyChangedDown(const View& child, + bool is_add, bool has_widget); + + // Notifies |target| that |child| was added to or removed from |this|. + // |has_widget| is true iff |this| is in a widget. void CallViewNotification(View* target, - View* parent, - View* child, + const View& child, bool is_add, bool has_widget); @@ -338,7 +366,8 @@ class View { // the hierarchy beneath it. void Paint(gfx::Canvas* canvas); - // Input -------------------------------------------------------------- + // Input --------------------------------------------------------------------- + // These methods are designed to be called by the RootView. The RootView // should limit its interaction with the View to these methods and the public // API. @@ -354,6 +383,7 @@ class View { void InitFocusSiblings(View* child, size_t index); // Drag & Drop --------------------------------------------------------------- + int GetDragOperations(const gfx::Point& point); void WriteDragData(const gfx::Point& point, OSExchangeData* data); void StartShellDrag(const MouseEvent& event, const gfx::Point& press_point); @@ -399,7 +429,7 @@ class View { View* parent_; // The View's children. - ViewVector children_; + Views children_; // Focus --------------------------------------------------------------------- diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc index 3d5e954..202b223 100644 --- a/ui/views/view_unittest.cc +++ b/ui/views/view_unittest.cc @@ -25,7 +25,7 @@ TEST_F(ViewTest, SizeAndDisposition) { EXPECT_TRUE(v.bounds().IsEmpty()); EXPECT_TRUE(v.visible()); - v.SetBoundsRect(gfx::Rect(10, 10, 200, 200)); + v.SetBounds(gfx::Rect(10, 10, 200, 200)); EXPECT_EQ(200, v.width()); EXPECT_TRUE(v.GetPreferredSize().IsEmpty()); @@ -34,24 +34,24 @@ TEST_F(ViewTest, SizeAndDisposition) { TEST_F(ViewTest, TreeOperations) { View v; EXPECT_EQ(NULL, v.GetWidget()); - EXPECT_EQ(0, v.child_count()); + EXPECT_TRUE(v.children_empty()); View child1; v.AddChildView(&child1); - EXPECT_EQ(1, v.child_count()); + EXPECT_EQ(1, v.children_size()); EXPECT_EQ(&v, child1.parent()); View child2; v.AddChildViewAt(&child2, 0); - EXPECT_EQ(2, v.child_count()); + EXPECT_EQ(2, v.children_size()); EXPECT_EQ(child1.parent(), child2.parent()); - v.RemoveChildView(&child2); - EXPECT_EQ(1, v.child_count()); + v.RemoveChildView(&child2, false); + EXPECT_EQ(1, v.children_size()); EXPECT_EQ(NULL, child2.parent()); //v.RemoveAllChildViews(false); - //EXPECT_EQ(0, v.child_count()); + //EXPECT_TRUE(v.children_empty()); } class ObserverView : public View { @@ -159,38 +159,38 @@ TEST_F(ViewTest, HierarchyObserver) { } */ -TEST_F(ViewTest, Ids) { - const int kV1Id = 1; - const int kV2Id = 2; - const int kV3Id = 3; - const int kV4Id = 4; - const int kV5Id = 5; - const int kGroupId = 1; +TEST_F(ViewTest, IDs) { + const int kV1ID = 1; + const int kV2ID = 2; + const int kV3ID = 3; + const int kV4ID = 4; + const int kV5ID = 5; + const int kGroupID = 1; View v1; - v1.set_id(kV1Id); + v1.set_id(kV1ID); View v2; - v2.set_id(kV2Id); + v2.set_id(kV2ID); View v3; - v3.set_id(kV3Id); - v3.set_group(kGroupId); + v3.set_id(kV3ID); + v3.set_group(kGroupID); View v4; - v4.set_id(kV4Id); - v4.set_group(kGroupId); + v4.set_id(kV4ID); + v4.set_group(kGroupID); v1.AddChildView(&v2); v2.AddChildView(&v3); v2.AddChildView(&v4); - EXPECT_EQ(&v4, v1.GetViewById(kV4Id)); - EXPECT_EQ(&v1, v1.GetViewById(kV1Id)); - EXPECT_EQ(NULL, v1.GetViewById(kV5Id)); // No V5 exists. - - View::ViewVector vec; - v1.GetViewsWithGroup(kGroupId, &vec); - EXPECT_EQ(2, vec.size()); - View::ViewVector::const_iterator it = find(vec.begin(), vec.end(), &v3); - EXPECT_NE(vec.end(), it); - it = find(vec.begin(), vec.end(), &v4); - EXPECT_NE(vec.end(), it); + EXPECT_EQ(&v4, v1.GetViewByID(kV4ID)); + EXPECT_EQ(&v1, v1.GetViewByID(kV1ID)); + EXPECT_EQ(NULL, v1.GetViewByID(kV5ID)); // No V5 exists. + + View::Views views; + v1.GetViewsInGroup(kGroupID, &views); + EXPECT_EQ(2, views.size()); + View::Views::const_iterator it = std::find(views.begin(), views.end(), &v3); + EXPECT_NE(views.end(), it); + it = std::find(views.begin(), views.end(), &v4); + EXPECT_NE(views.end(), it); } TEST_F(ViewTest, EventHandlers) { diff --git a/ui/views/views.gyp b/ui/views/views.gyp index 1778464..4308183 100644 --- a/ui/views/views.gyp +++ b/ui/views/views.gyp @@ -48,8 +48,8 @@ 'dependencies': [ '<(DEPTH)/app/app.gyp:app_base', '<(DEPTH)/app/app.gyp:app_strings', - '<(DEPTH)/gfx/gfx.gyp:gfx', '<(DEPTH)/skia/skia.gyp:skia', + '<(DEPTH)/ui/gfx/gfx.gyp:gfx', ], 'sources': [ 'events/accelerator.cc', diff --git a/ui/views/widget/root_view_unittest.cc b/ui/views/widget/root_view_unittest.cc index 71b2161..392ad58 100644 --- a/ui/views/widget/root_view_unittest.cc +++ b/ui/views/widget/root_view_unittest.cc @@ -32,7 +32,7 @@ TEST_F(RootViewTest, FocusedViewResetOnViewRemoval) { EXPECT_TRUE(focus_manager != NULL); EXPECT_EQ(&v, focus_manager->focused_view()); - v.parent()->RemoveChildView(&v); + v.parent()->RemoveChildView(&v, false); EXPECT_NE(&v, focus_manager->focused_view()); EXPECT_EQ(NULL, focus_manager->focused_view()); diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc index a03e9ff..3b2746a 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -161,7 +161,7 @@ void Widget::OnMouseCaptureLost() { bool Widget::OnMouseEvent(const MouseEvent& event) { last_mouse_event_was_move_ = false; switch (event.type()) { - case ui::ET_MOUSE_PRESSED: + case ui::Event::ET_MOUSE_PRESSED: if (root_view_->OnMousePressed(event)) { is_mouse_button_pressed_ = true; if (!native_widget_->HasMouseCapture()) @@ -169,7 +169,7 @@ bool Widget::OnMouseEvent(const MouseEvent& event) { return true; } return false; - case ui::ET_MOUSE_RELEASED: + case ui::Event::ET_MOUSE_RELEASED: // TODO(beng): NativeWidgetGtk should not call this function if drag data // exists, see comment in this function in WidgetGtk. // Release the capture first, that way we don't get confused if @@ -181,13 +181,13 @@ bool Widget::OnMouseEvent(const MouseEvent& event) { is_mouse_button_pressed_ = false; root_view_->OnMouseReleased(event); return true; - case ui::ET_MOUSE_MOVED: + case ui::Event::ET_MOUSE_MOVED: if (native_widget_->HasMouseCapture() && is_mouse_button_pressed_) { last_mouse_event_was_move_ = false; root_view_->OnMouseDragged(event); } else { gfx::Point screen_loc(event.location()); - View::ConvertPointToScreen(root_view_.get(), &screen_loc); + View::ConvertPointToScreen(*root_view_, &screen_loc); if (last_mouse_event_was_move_ && last_mouse_event_position_ == screen_loc) { // Don't generate a mouse event for the same location as the last. @@ -198,7 +198,7 @@ bool Widget::OnMouseEvent(const MouseEvent& event) { root_view_->OnMouseMoved(event); } break; - case ui::ET_MOUSE_EXITED: + case ui::Event::ET_MOUSE_EXITED: root_view_->OnMouseExited(event); return true; } |