• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/ui/views/dropdown_bar_host.h"
6 
7 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
8 #include "chrome/browser/ui/views/frame/browser_view.h"
9 #include "content/browser/renderer_host/render_view_host.h"
10 #include "content/browser/tab_contents/tab_contents.h"
11 #include "content/browser/tab_contents/tab_contents_view.h"
12 #include "ui/base/keycodes/keyboard_code_conversion_win.h"
13 #include "views/controls/scrollbar/native_scroll_bar.h"
14 #include "views/widget/widget_win.h"
15 
GetKeyboardEvent(const TabContents * contents,const views::KeyEvent & key_event)16 NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent(
17      const TabContents* contents,
18      const views::KeyEvent& key_event) {
19   HWND hwnd = contents->GetContentNativeView();
20   WORD key = WindowsKeyCodeForKeyboardCode(key_event.key_code());
21 
22   return NativeWebKeyboardEvent(hwnd, key_event.native_event().message, key, 0);
23 }
24 
CreateHost()25 views::Widget* DropdownBarHost::CreateHost() {
26   views::WidgetWin* widget = new views::WidgetWin();
27   views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL);
28   // Don't let WidgetWin manage our lifetime. We want our lifetime to
29   // coincide with TabContents.
30   params.delete_on_destroy = false;
31   widget->SetCreateParams(params);
32   return widget;
33 }
34 
SetWidgetPositionNative(const gfx::Rect & new_pos,bool no_redraw)35 void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos,
36                                               bool no_redraw) {
37   gfx::Rect window_rect = host_->GetWindowScreenBounds();
38   DWORD swp_flags = SWP_NOOWNERZORDER;
39   if (!window_rect.IsEmpty())
40     swp_flags |= SWP_NOSIZE;
41   if (no_redraw)
42     swp_flags |= SWP_NOREDRAW;
43   if (!host_->IsVisible())
44     swp_flags |= SWP_SHOWWINDOW;
45 
46   ::SetWindowPos(host_->GetNativeView(), HWND_TOP, new_pos.x(), new_pos.y(),
47                  new_pos.width(), new_pos.height(), swp_flags);
48 }
49