| OLD | NEW |
| 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/views/window/non_client_view.h" | 5 #include "ui/views/window/non_client_view.h" |
| 6 | 6 |
| 7 #include "ui/accessibility/ax_view_state.h" | 7 #include "ui/accessibility/ax_view_state.h" |
| 8 #include "ui/base/hit_test.h" | 8 #include "ui/base/hit_test.h" |
| 9 #include "ui/gfx/rect_conversions.h" | 9 #include "ui/gfx/rect_conversions.h" |
| 10 #include "ui/views/rect_based_targeting_utils.h" | 10 #include "ui/views/rect_based_targeting_utils.h" |
| 11 #include "ui/views/view_targeter.h" |
| 11 #include "ui/views/widget/root_view.h" | 12 #include "ui/views/widget/root_view.h" |
| 12 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 13 #include "ui/views/window/client_view.h" | 14 #include "ui/views/window/client_view.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| 17 // static | 18 // static |
| 18 const char NonClientFrameView::kViewClassName[] = | 19 const char NonClientFrameView::kViewClassName[] = |
| 19 "ui/views/window/NonClientFrameView"; | 20 "ui/views/window/NonClientFrameView"; |
| 20 | 21 |
| 21 const char NonClientView::kViewClassName[] = | 22 const char NonClientView::kViewClassName[] = |
| 22 "ui/views/window/NonClientView"; | 23 "ui/views/window/NonClientView"; |
| 23 | 24 |
| 24 // The frame view and the client view are always at these specific indices, | 25 // The frame view and the client view are always at these specific indices, |
| 25 // because the RootView message dispatch sends messages to items higher in the | 26 // because the RootView message dispatch sends messages to items higher in the |
| 26 // z-order first and we always want the client view to have first crack at | 27 // z-order first and we always want the client view to have first crack at |
| 27 // handling mouse messages. | 28 // handling mouse messages. |
| 28 static const int kFrameViewIndex = 0; | 29 static const int kFrameViewIndex = 0; |
| 29 static const int kClientViewIndex = 1; | 30 static const int kClientViewIndex = 1; |
| 30 // The overlay view is always on top (index == child_count() - 1). | 31 // The overlay view is always on top (index == child_count() - 1). |
| 31 | 32 |
| 32 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 33 // NonClientView, public: | 34 // NonClientView, public: |
| 34 | 35 |
| 35 NonClientView::NonClientView() | 36 NonClientView::NonClientView() |
| 36 : client_view_(NULL), | 37 : client_view_(NULL), |
| 37 overlay_view_(NULL) { | 38 overlay_view_(NULL) { |
| 39 SetEventTargeter( |
| 40 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 38 } | 41 } |
| 39 | 42 |
| 40 NonClientView::~NonClientView() { | 43 NonClientView::~NonClientView() { |
| 41 // This value may have been reset before the window hierarchy shuts down, | 44 // This value may have been reset before the window hierarchy shuts down, |
| 42 // so we need to manually remove it. | 45 // so we need to manually remove it. |
| 43 RemoveChildView(frame_view_.get()); | 46 RemoveChildView(frame_view_.get()); |
| 44 } | 47 } |
| 45 | 48 |
| 46 void NonClientView::SetFrameView(NonClientFrameView* frame_view) { | 49 void NonClientView::SetFrameView(NonClientFrameView* frame_view) { |
| 47 // See comment in header about ownership. | 50 // See comment in header about ownership. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 182 |
| 180 void NonClientView::GetAccessibleState(ui::AXViewState* state) { | 183 void NonClientView::GetAccessibleState(ui::AXViewState* state) { |
| 181 state->role = ui::AX_ROLE_CLIENT; | 184 state->role = ui::AX_ROLE_CLIENT; |
| 182 state->name = accessible_name_; | 185 state->name = accessible_name_; |
| 183 } | 186 } |
| 184 | 187 |
| 185 const char* NonClientView::GetClassName() const { | 188 const char* NonClientView::GetClassName() const { |
| 186 return kViewClassName; | 189 return kViewClassName; |
| 187 } | 190 } |
| 188 | 191 |
| 189 View* NonClientView::GetEventHandlerForRect(const gfx::Rect& rect) { | 192 // Terry - move to right place in file |
| 193 View* NonClientView::TargetForRect(View* root, |
| 194 const gfx::Rect& rect) { |
| 195 CHECK_EQ(root, this); |
| 196 |
| 190 if (!UsePointBasedTargeting(rect)) | 197 if (!UsePointBasedTargeting(rect)) |
| 191 return View::GetEventHandlerForRect(rect); | 198 return ViewTargeterDelegate::TargetForRect(root, rect); |
| 192 | 199 |
| 193 // Because of the z-ordering of our child views (the client view is positioned | 200 // Because of the z-ordering of our child views (the client view is positioned |
| 194 // over the non-client frame view, if the client view ever overlaps the frame | 201 // over the non-client frame view, if the client view ever overlaps the frame |
| 195 // view visually (as it does for the browser window), then it will eat | 202 // view visually (as it does for the browser window), then it will eat |
| 196 // events for the window controls. We override this method here so that we can | 203 // events for the window controls. We override this method here so that we can |
| 197 // detect this condition and re-route the events to the non-client frame view. | 204 // detect this condition and re-route the events to the non-client frame view. |
| 198 // The assumption is that the frame view's implementation of HitTest will only | 205 // The assumption is that the frame view's implementation of HitTest will only |
| 199 // return true for area not occupied by the client view. | 206 // return true for area not occupied by the client view. |
| 200 if (frame_view_->parent() == this) { | 207 if (frame_view_->parent() == this) { |
| 201 // During the reset of the frame_view_ it's possible to be in this code | 208 // During the reset of the frame_view_ it's possible to be in this code |
| 202 // after it's been removed from the view hierarchy but before it's been | 209 // after it's been removed from the view hierarchy but before it's been |
| 203 // removed from the NonClientView. | 210 // removed from the NonClientView. |
| 204 gfx::RectF rect_in_child_coords_f(rect); | 211 gfx::RectF rect_in_child_coords_f(rect); |
| 205 View::ConvertRectToTarget(this, frame_view_.get(), &rect_in_child_coords_f); | 212 View::ConvertRectToTarget(this, frame_view_.get(), &rect_in_child_coords_f); |
| 206 gfx::Rect rect_in_child_coords = gfx::ToEnclosingRect( | 213 gfx::Rect rect_in_child_coords = gfx::ToEnclosingRect( |
| 207 rect_in_child_coords_f); | 214 rect_in_child_coords_f); |
| 208 if (frame_view_->HitTestRect(rect_in_child_coords)) | 215 if (frame_view_->HitTestRect(rect_in_child_coords)) |
| 209 return frame_view_->GetEventHandlerForRect(rect_in_child_coords); | 216 return frame_view_->GetEventHandlerForRect(rect_in_child_coords); |
| 210 } | 217 } |
| 211 | 218 |
| 212 return View::GetEventHandlerForRect(rect); | 219 return ViewTargeterDelegate::TargetForRect(root, rect); |
| 213 } | 220 } |
| 214 | 221 |
| 215 View* NonClientView::GetTooltipHandlerForPoint(const gfx::Point& point) { | 222 View* NonClientView::GetTooltipHandlerForPoint(const gfx::Point& point) { |
| 216 // The same logic as for |GetEventHandlerForRect()| applies here. | 223 // The same logic as for |GetEventHandlerForRect()| applies here. |
| 217 if (frame_view_->parent() == this) { | 224 if (frame_view_->parent() == this) { |
| 218 // During the reset of the frame_view_ it's possible to be in this code | 225 // During the reset of the frame_view_ it's possible to be in this code |
| 219 // after it's been removed from the view hierarchy but before it's been | 226 // after it's been removed from the view hierarchy but before it's been |
| 220 // removed from the NonClientView. | 227 // removed from the NonClientView. |
| 221 gfx::Point point_in_child_coords(point); | 228 gfx::Point point_in_child_coords(point); |
| 222 View::ConvertPointToTarget(this, frame_view_.get(), &point_in_child_coords); | 229 View::ConvertPointToTarget(this, frame_view_.get(), &point_in_child_coords); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } else { | 301 } else { |
| 295 return HTNOWHERE; | 302 return HTNOWHERE; |
| 296 } | 303 } |
| 297 | 304 |
| 298 // If the window can't be resized, there are no resize boundaries, just | 305 // If the window can't be resized, there are no resize boundaries, just |
| 299 // window borders. | 306 // window borders. |
| 300 return can_resize ? component : HTBORDER; | 307 return can_resize ? component : HTBORDER; |
| 301 } | 308 } |
| 302 | 309 |
| 303 //////////////////////////////////////////////////////////////////////////////// | 310 //////////////////////////////////////////////////////////////////////////////// |
| 304 // NonClientFrameView, View overrides: | 311 // NonClientFrameView, ViewTargeterDelegate overrides: |
| 305 | 312 |
| 306 bool NonClientFrameView::HitTestRect(const gfx::Rect& rect) const { | 313 bool NonClientFrameView::DoesIntersectRect(const View* target, |
| 314 const gfx::Rect& rect) const { |
| 315 CHECK_EQ(target, this); |
| 316 |
| 307 // For the default case, we assume the non-client frame view never overlaps | 317 // For the default case, we assume the non-client frame view never overlaps |
| 308 // the client view. | 318 // the client view. |
| 309 return !GetWidget()->client_view()->bounds().Intersects(rect); | 319 return !GetWidget()->client_view()->bounds().Intersects(rect); |
| 310 } | 320 } |
| 311 | 321 |
| 312 //////////////////////////////////////////////////////////////////////////////// | 322 //////////////////////////////////////////////////////////////////////////////// |
| 313 // NonClientFrameView, protected: | 323 // NonClientFrameView, protected: |
| 314 | 324 |
| 315 void NonClientFrameView::GetAccessibleState(ui::AXViewState* state) { | 325 void NonClientFrameView::GetAccessibleState(ui::AXViewState* state) { |
| 316 state->role = ui::AX_ROLE_CLIENT; | 326 state->role = ui::AX_ROLE_CLIENT; |
| 317 } | 327 } |
| 318 | 328 |
| 319 const char* NonClientFrameView::GetClassName() const { | 329 const char* NonClientFrameView::GetClassName() const { |
| 320 return kViewClassName; | 330 return kViewClassName; |
| 321 } | 331 } |
| 322 | 332 |
| 323 void NonClientFrameView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 333 void NonClientFrameView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 324 // Overridden to do nothing. The NonClientView manually calls Layout on the | 334 // Overridden to do nothing. The NonClientView manually calls Layout on the |
| 325 // FrameView when it is itself laid out, see comment in NonClientView::Layout. | 335 // FrameView when it is itself laid out, see comment in NonClientView::Layout. |
| 326 } | 336 } |
| 327 | 337 |
| 328 NonClientFrameView::NonClientFrameView() : inactive_rendering_disabled_(false) { | 338 NonClientFrameView::NonClientFrameView() : inactive_rendering_disabled_(false) { |
| 339 // Terry - the right place for this? |
| 340 SetEventTargeter( |
| 341 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 329 } | 342 } |
| 330 | 343 |
| 331 } // namespace views | 344 } // namespace views |
| OLD | NEW |