OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/views/non_client_view.h" | 5 #include "chrome/views/non_client_view.h" |
6 #include "chrome/views/widget.h" | 6 |
| 7 #include "chrome/common/win_util.h" |
| 8 #include "chrome/views/root_view.h" |
| 9 #include "chrome/views/window.h" |
7 | 10 |
8 namespace views { | 11 namespace views { |
9 | 12 |
10 const int NonClientView::kFrameShadowThickness = 1; | 13 const int NonClientFrameView::kFrameShadowThickness = 1; |
11 const int NonClientView::kClientEdgeThickness = 1; | 14 const int NonClientFrameView::kClientEdgeThickness = 1; |
| 15 |
| 16 // The frame view and the client view are always at these specific indices, |
| 17 // because the RootView message dispatch sends messages to items higher in the |
| 18 // z-order first and we always want the client view to have first crack at |
| 19 // handling mouse messages. |
| 20 static const int kFrameViewIndex = 0; |
| 21 static const int kClientViewIndex = 1; |
12 | 22 |
13 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
14 // NonClientView, public: | 24 // NonClientView, public: |
15 | 25 |
16 NonClientView::NonClientView() : paint_as_active_(false) { | 26 NonClientView::NonClientView(Window* frame) |
| 27 : frame_(frame), |
| 28 client_view_(NULL), |
| 29 use_native_frame_(win_util::ShouldUseVistaFrame()) { |
17 } | 30 } |
18 | 31 |
19 NonClientView::~NonClientView() { | 32 NonClientView::~NonClientView() { |
| 33 // This value may have been reset before the window hierarchy shuts down, |
| 34 // so we need to manually remove it. |
| 35 RemoveChildView(frame_view_.get()); |
| 36 } |
| 37 |
| 38 void NonClientView::SetFrameView(NonClientFrameView* frame_view) { |
| 39 // See comment in header about ownership. |
| 40 frame_view->SetParentOwned(false); |
| 41 if (frame_view_.get()) |
| 42 RemoveChildView(frame_view_.get()); |
| 43 frame_view_.reset(frame_view); |
| 44 if (GetParent()) |
| 45 AddChildView(kFrameViewIndex, frame_view_.get()); |
20 } | 46 } |
21 | 47 |
22 bool NonClientView::CanClose() const { | 48 bool NonClientView::CanClose() const { |
23 return client_view_->CanClose(); | 49 return client_view_->CanClose(); |
24 } | 50 } |
25 | 51 |
26 void NonClientView::WindowClosing() { | 52 void NonClientView::WindowClosing() { |
27 client_view_->WindowClosing(); | 53 client_view_->WindowClosing(); |
28 } | 54 } |
29 | 55 |
30 bool NonClientView::UseNativeFrame() const { | 56 void NonClientView::SystemThemeChanged() { |
31 return true; | 57 // The window may try to paint in SetUseNativeFrame, and as a result it can |
| 58 // get into a state where it is very unhappy with itself - rendering black |
| 59 // behind the entire client area. This is because for some reason the |
| 60 // SkPorterDuff::kClear_mode erase done in the RootView thinks the window is |
| 61 // still opaque. So, to work around this we hide the window as soon as we can |
| 62 // (now), saving off its placement so it can be properly restored once |
| 63 // everything has settled down. |
| 64 WINDOWPLACEMENT saved_window_placement; |
| 65 saved_window_placement.length = sizeof(WINDOWPLACEMENT); |
| 66 GetWindowPlacement(frame_->GetHWND(), &saved_window_placement); |
| 67 frame_->Hide(); |
| 68 |
| 69 SetUseNativeFrame(win_util::ShouldUseVistaFrame()); |
| 70 |
| 71 // Now that we've updated the frame, we'll want to restore our saved placement |
| 72 // since the display should have settled down and we can be properly rendered. |
| 73 SetWindowPlacement(frame_->GetHWND(), &saved_window_placement); |
32 } | 74 } |
33 | 75 |
34 gfx::Rect NonClientView::CalculateClientAreaBounds(int width, | 76 void NonClientView::SetUseNativeFrame(bool use_native_frame) { |
35 int height) const { | 77 use_native_frame_ = use_native_frame; |
36 return gfx::Rect(); | 78 SetFrameView(frame_->CreateFrameViewForWindow()); |
| 79 GetRootView()->ThemeChanged(); |
| 80 Layout(); |
| 81 SchedulePaint(); |
| 82 frame_->UpdateFrameAfterFrameChange(); |
37 } | 83 } |
38 | 84 |
39 gfx::Size NonClientView::CalculateWindowSizeForClientSize(int width, | 85 bool NonClientView::UseNativeFrame() const { |
40 int height) const { | 86 // The frame view may always require a custom frame, e.g. Constrained Windows. |
41 return gfx::Size(); | 87 bool always_use_custom_frame = |
| 88 frame_view_.get() && frame_view_->AlwaysUseCustomFrame(); |
| 89 return !always_use_custom_frame && use_native_frame_; |
| 90 } |
| 91 |
| 92 void NonClientView::DisableInactiveRendering(bool disable) { |
| 93 frame_view_->DisableInactiveRendering(disable); |
| 94 } |
| 95 |
| 96 gfx::Rect NonClientView::GetWindowBoundsForClientBounds( |
| 97 const gfx::Rect client_bounds) const { |
| 98 return frame_view_->GetWindowBoundsForClientBounds(client_bounds); |
42 } | 99 } |
43 | 100 |
44 gfx::Point NonClientView::GetSystemMenuPoint() const { | 101 gfx::Point NonClientView::GetSystemMenuPoint() const { |
45 CPoint temp(0, -kFrameShadowThickness); | 102 return frame_view_->GetSystemMenuPoint(); |
46 MapWindowPoints(GetWidget()->GetHWND(), HWND_DESKTOP, &temp, 1); | |
47 return gfx::Point(temp); | |
48 } | 103 } |
49 | 104 |
50 int NonClientView::NonClientHitTest(const gfx::Point& point) { | 105 int NonClientView::NonClientHitTest(const gfx::Point& point) { |
51 return client_view_->NonClientHitTest(point); | 106 // Sanity check. |
| 107 if (!bounds().Contains(point)) |
| 108 return HTNOWHERE; |
| 109 |
| 110 // The ClientView gets first crack, since it overlays the NonClientFrameView |
| 111 // in the display stack. |
| 112 int frame_component = client_view_->NonClientHitTest(point); |
| 113 if (frame_component != HTNOWHERE) |
| 114 return frame_component; |
| 115 |
| 116 // Finally ask the NonClientFrameView. It's at the back of the display stack |
| 117 // so it gets asked last. |
| 118 return frame_view_->NonClientHitTest(point); |
52 } | 119 } |
53 | 120 |
54 void NonClientView::GetWindowMask(const gfx::Size& size, | 121 void NonClientView::GetWindowMask(const gfx::Size& size, |
55 gfx::Path* window_mask) { | 122 gfx::Path* window_mask) { |
| 123 frame_view_->GetWindowMask(size, window_mask); |
56 } | 124 } |
57 | 125 |
58 void NonClientView::EnableClose(bool enable) { | 126 void NonClientView::EnableClose(bool enable) { |
| 127 frame_view_->EnableClose(enable); |
59 } | 128 } |
60 | 129 |
61 void NonClientView::ResetWindowControls() { | 130 void NonClientView::ResetWindowControls() { |
| 131 frame_view_->ResetWindowControls(); |
62 } | 132 } |
63 | 133 |
64 | |
65 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
66 // NonClientView, View overrides: | 135 // NonClientView, View overrides: |
67 | 136 |
68 gfx::Size NonClientView::GetPreferredSize() { | 137 gfx::Size NonClientView::GetPreferredSize() { |
69 return client_view_->GetPreferredSize(); | 138 return client_view_->GetPreferredSize(); |
70 } | 139 } |
71 | 140 |
72 void NonClientView::Layout() { | 141 void NonClientView::Layout() { |
73 client_view_->SetBounds(0, 0, width(), height()); | 142 // First layout the NonClientFrameView, which determines the size of the |
| 143 // ClientView... |
| 144 frame_view_->SetBounds(0, 0, width(), height()); |
| 145 |
| 146 // Then layout the ClientView, using those bounds. |
| 147 client_view_->SetBounds(frame_view_->GetBoundsForClientView()); |
74 } | 148 } |
75 | 149 |
76 void NonClientView::ViewHierarchyChanged(bool is_add, View* parent, | 150 void NonClientView::ViewHierarchyChanged(bool is_add, View* parent, |
77 View* child) { | 151 View* child) { |
78 // Add our Client View as we are added to the Widget so that if we are | 152 // Add our two child views here as we are added to the Widget so that if we |
79 // subsequently resized all the parent-child relationships are established. | 153 // are subsequently resized all the parent-child relationships are |
80 if (is_add && GetWidget() && child == this) | 154 // established. |
81 AddChildView(client_view_); | 155 if (is_add && GetWidget() && child == this) { |
| 156 AddChildView(kFrameViewIndex, frame_view_.get()); |
| 157 AddChildView(kClientViewIndex, client_view_); |
| 158 } |
82 } | 159 } |
83 | 160 |
84 //////////////////////////////////////////////////////////////////////////////// | 161 //////////////////////////////////////////////////////////////////////////////// |
85 // NonClientView, protected: | 162 // NonClientFrameView, protected: |
86 | 163 |
87 int NonClientView::GetHTComponentForFrame(const gfx::Point& point, | 164 int NonClientFrameView::GetHTComponentForFrame(const gfx::Point& point, |
88 int top_resize_border_height, | 165 int top_resize_border_height, |
89 int resize_border_thickness, | 166 int resize_border_thickness, |
90 int top_resize_corner_height, | 167 int top_resize_corner_height, |
91 int resize_corner_width, | 168 int resize_corner_width, |
92 bool can_resize) { | 169 bool can_resize) { |
93 // Tricky: In XP, native behavior is to return HTTOPLEFT and HTTOPRIGHT for | 170 // Tricky: In XP, native behavior is to return HTTOPLEFT and HTTOPRIGHT for |
94 // a |resize_corner_size|-length strip of both the side and top borders, but | 171 // a |resize_corner_size|-length strip of both the side and top borders, but |
95 // only to return HTBOTTOMLEFT/HTBOTTOMRIGHT along the bottom border + corner | 172 // only to return HTBOTTOMLEFT/HTBOTTOMRIGHT along the bottom border + corner |
96 // (not the side border). Vista goes further and doesn't return these on any | 173 // (not the side border). Vista goes further and doesn't return these on any |
97 // of the side borders. We allow callers to match either behavior. | 174 // of the side borders. We allow callers to match either behavior. |
98 int component; | 175 int component; |
99 if (point.x() < resize_border_thickness) { | 176 if (point.x() < resize_border_thickness) { |
100 if (point.y() < top_resize_corner_height) | 177 if (point.y() < top_resize_corner_height) |
101 component = HTTOPLEFT; | 178 component = HTTOPLEFT; |
102 else if (point.y() >= (height() - resize_border_thickness)) | 179 else if (point.y() >= (height() - resize_border_thickness)) |
(...skipping 25 matching lines...) Expand all Loading... |
128 return HTNOWHERE; | 205 return HTNOWHERE; |
129 } | 206 } |
130 | 207 |
131 // If the window can't be resized, there are no resize boundaries, just | 208 // If the window can't be resized, there are no resize boundaries, just |
132 // window borders. | 209 // window borders. |
133 return can_resize ? component : HTBORDER; | 210 return can_resize ? component : HTBORDER; |
134 } | 211 } |
135 | 212 |
136 } // namespace views | 213 } // namespace views |
137 | 214 |
OLD | NEW |