| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/native_control.h" | 5 #include "views/controls/native_control.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlapp.h> | 8 #include <atlapp.h> |
| 9 #include <atlcrack.h> | 9 #include <atlcrack.h> |
| 10 #include <atlframe.h> | 10 #include <atlframe.h> |
| 11 #include <atlmisc.h> | 11 #include <atlmisc.h> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "ui/base/accessibility/accessibility_types.h" | 15 #include "ui/base/accessibility/accessibility_types.h" |
| 16 #include "ui/base/keycodes/keyboard_code_conversion_win.h" |
| 16 #include "ui/base/keycodes/keyboard_codes.h" | 17 #include "ui/base/keycodes/keyboard_codes.h" |
| 17 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | |
| 18 #include "ui/base/l10n/l10n_util_win.h" | 18 #include "ui/base/l10n/l10n_util_win.h" |
| 19 #include "ui/base/view_prop.h" | 19 #include "ui/base/view_prop.h" |
| 20 #include "ui/base/win/hwnd_util.h" | 20 #include "ui/base/win/hwnd_util.h" |
| 21 #include "views/background.h" | 21 #include "views/background.h" |
| 22 #include "views/border.h" | 22 #include "views/border.h" |
| 23 #include "views/controls/native/native_view_host.h" | 23 #include "views/controls/native/native_view_host.h" |
| 24 #include "views/focus/focus_manager.h" | 24 #include "views/focus/focus_manager.h" |
| 25 #include "views/widget/widget.h" | 25 #include "views/widget/widget.h" |
| 26 | 26 |
| 27 using ui::ViewProp; | 27 using ui::ViewProp; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 DISALLOW_COPY_AND_ASSIGN(NativeControlContainer); | 172 DISALLOW_COPY_AND_ASSIGN(NativeControlContainer); |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 NativeControl::NativeControl() : hwnd_view_(NULL), | 175 NativeControl::NativeControl() : hwnd_view_(NULL), |
| 176 container_(NULL), | 176 container_(NULL), |
| 177 fixed_width_(-1), | 177 fixed_width_(-1), |
| 178 horizontal_alignment_(CENTER), | 178 horizontal_alignment_(CENTER), |
| 179 fixed_height_(-1), | 179 fixed_height_(-1), |
| 180 vertical_alignment_(CENTER) { | 180 vertical_alignment_(CENTER) { |
| 181 enabled_ = true; | |
| 182 focusable_ = true; | 181 focusable_ = true; |
| 183 } | 182 } |
| 184 | 183 |
| 185 NativeControl::~NativeControl() { | 184 NativeControl::~NativeControl() { |
| 186 if (container_) { | 185 if (container_) { |
| 187 container_->ResetParent(); | 186 container_->ResetParent(); |
| 188 ::DestroyWindow(*container_); | 187 ::DestroyWindow(*container_); |
| 189 } | 188 } |
| 190 } | 189 } |
| 191 | 190 |
| 192 void NativeControl::ValidateNativeControl() { | 191 void NativeControl::ValidateNativeControl() { |
| 193 if (hwnd_view_ == NULL) { | 192 if (hwnd_view_ == NULL) { |
| 194 hwnd_view_ = new NativeViewHost; | 193 hwnd_view_ = new NativeViewHost; |
| 195 AddChildView(hwnd_view_); | 194 AddChildView(hwnd_view_); |
| 196 } | 195 } |
| 197 | 196 |
| 198 if (!container_ && IsVisible()) { | 197 if (!container_ && IsVisible()) { |
| 199 container_ = new NativeControlContainer(this); | 198 container_ = new NativeControlContainer(this); |
| 200 container_->Init(); | 199 container_->Init(); |
| 201 hwnd_view_->Attach(*container_); | 200 hwnd_view_->Attach(*container_); |
| 202 if (!enabled_) | 201 if (!IsEnabled()) |
| 203 EnableWindow(GetNativeControlHWND(), enabled_); | 202 EnableWindow(GetNativeControlHWND(), IsEnabled()); |
| 204 | 203 |
| 205 // This message ensures that the focus border is shown. | 204 // This message ensures that the focus border is shown. |
| 206 ::SendMessage(container_->GetControl(), | 205 ::SendMessage(container_->GetControl(), |
| 207 WM_CHANGEUISTATE, | 206 WM_CHANGEUISTATE, |
| 208 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), | 207 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), |
| 209 0); | 208 0); |
| 210 } | 209 } |
| 211 } | 210 } |
| 212 | 211 |
| 213 void NativeControl::ViewHierarchyChanged(bool is_add, View *parent, | 212 void NativeControl::ViewHierarchyChanged(bool is_add, View *parent, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 if (f != IsVisible()) { | 304 if (f != IsVisible()) { |
| 306 View::SetVisible(f); | 305 View::SetVisible(f); |
| 307 if (!f && container_) { | 306 if (!f && container_) { |
| 308 ::DestroyWindow(*container_); | 307 ::DestroyWindow(*container_); |
| 309 } else if (f && !container_) { | 308 } else if (f && !container_) { |
| 310 ValidateNativeControl(); | 309 ValidateNativeControl(); |
| 311 } | 310 } |
| 312 } | 311 } |
| 313 } | 312 } |
| 314 | 313 |
| 315 void NativeControl::SetEnabled(bool enabled) { | 314 void NativeControl::OnEnabledChanged() { |
| 316 if (enabled_ != enabled) { | 315 View::OnEnabledChanged(); |
| 317 View::SetEnabled(enabled); | 316 if (GetNativeControlHWND()) |
| 318 if (GetNativeControlHWND()) { | 317 EnableWindow(GetNativeControlHWND(), IsEnabled()); |
| 319 EnableWindow(GetNativeControlHWND(), enabled_); | |
| 320 } | |
| 321 } | |
| 322 } | 318 } |
| 323 | 319 |
| 324 void NativeControl::OnPaint(gfx::Canvas* canvas) { | 320 void NativeControl::OnPaint(gfx::Canvas* canvas) { |
| 325 } | 321 } |
| 326 | 322 |
| 327 void NativeControl::VisibilityChanged(View* starting_from, bool is_visible) { | 323 void NativeControl::VisibilityChanged(View* starting_from, bool is_visible) { |
| 328 SetVisible(is_visible); | 324 SetVisible(is_visible); |
| 329 } | 325 } |
| 330 | 326 |
| 331 void NativeControl::SetFixedWidth(int width, Alignment alignment) { | 327 void NativeControl::SetFixedWidth(int width, Alignment alignment) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } else if (message == WM_DESTROY) { | 383 } else if (message == WM_DESTROY) { |
| 388 ui::SetWindowProc(window, reinterpret_cast<WNDPROC>(original_handler)); | 384 ui::SetWindowProc(window, reinterpret_cast<WNDPROC>(original_handler)); |
| 389 native_control->container_->prop_.reset(); | 385 native_control->container_->prop_.reset(); |
| 390 } | 386 } |
| 391 | 387 |
| 392 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, | 388 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, |
| 393 message, w_param, l_param); | 389 message, w_param, l_param); |
| 394 } | 390 } |
| 395 | 391 |
| 396 } // namespace views | 392 } // namespace views |
| OLD | NEW |