| 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 "chrome/browser/ui/views/dropdown_bar_host.h" | 5 #include "chrome/browser/ui/views/dropdown_bar_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/view_ids.h" | 9 #include "chrome/browser/ui/view_ids.h" |
| 10 #include "chrome/browser/ui/views/dropdown_bar_host_delegate.h" | 10 #include "chrome/browser/ui/views/dropdown_bar_host_delegate.h" |
| 11 #include "chrome/browser/ui/views/dropdown_bar_view.h" | 11 #include "chrome/browser/ui/views/dropdown_bar_view.h" |
| 12 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 13 #include "chrome/browser/ui/views/theme_copying_widget.h" | 13 #include "chrome/browser/ui/views/theme_copying_widget.h" |
| 14 #include "ui/events/keycodes/keyboard_codes.h" | 14 #include "ui/events/keycodes/keyboard_codes.h" |
| 15 #include "ui/gfx/animation/slide_animation.h" | 15 #include "ui/gfx/animation/slide_animation.h" |
| 16 #include "ui/gfx/scrollbar_size.h" | 16 #include "ui/gfx/scrollbar_size.h" |
| 17 #include "ui/views/focus/external_focus_tracker.h" | 17 #include "ui/views/focus/external_focus_tracker.h" |
| 18 #include "ui/views/focus/view_storage.h" | 18 #include "ui/views/focus/view_storage.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 bool DropdownBarHost::disable_animations_during_testing_ = false; | 22 bool DropdownBarHost::disable_animations_during_testing_ = false; |
| 23 | 23 |
| 24 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
| 25 // DropdownBarHost, public: | 25 // DropdownBarHost, public: |
| 26 | 26 |
| 27 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) | 27 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) |
| 28 : browser_view_(browser_view), | 28 : browser_view_(browser_view), |
| 29 clip_view_(new views::View()), | 29 view_(nullptr), |
| 30 view_(NULL), | 30 delegate_(nullptr), |
| 31 delegate_(NULL), | 31 focus_manager_(nullptr), |
| 32 focus_manager_(NULL), | |
| 33 esc_accel_target_registered_(false), | 32 esc_accel_target_registered_(false), |
| 34 is_visible_(false) { | 33 is_visible_(false) {} |
| 35 // The |clip_view_| must paint to a layer so that it can clip descendent Views | |
| 36 // which also paint to a Layer. | |
| 37 clip_view_->SetPaintToLayer(true); | |
| 38 clip_view_->SetFillsBoundsOpaquely(false); | |
| 39 clip_view_->layer()->SetMasksToBounds(true); | |
| 40 } | |
| 41 | 34 |
| 42 void DropdownBarHost::Init(views::View* host_view, | 35 void DropdownBarHost::Init(views::View* host_view, |
| 43 views::View* view, | 36 views::View* view, |
| 44 DropdownBarHostDelegate* delegate) { | 37 DropdownBarHostDelegate* delegate) { |
| 45 DCHECK(view); | 38 DCHECK(view); |
| 46 DCHECK(delegate); | 39 DCHECK(delegate); |
| 47 | 40 |
| 48 view_ = view; | 41 view_ = view; |
| 49 delegate_ = delegate; | 42 delegate_ = delegate; |
| 50 | 43 |
| 44 // The |clip_view| exists to paint to a layer so that it can clip descendent |
| 45 // Views which also paint to a Layer. |
| 46 scoped_ptr<views::View> clip_view(new views::View()); |
| 47 clip_view->SetPaintToLayer(true); |
| 48 clip_view->SetFillsBoundsOpaquely(false); |
| 49 clip_view->layer()->SetMasksToBounds(true); |
| 50 clip_view->AddChildView(view_); |
| 51 |
| 51 // Initialize the host. | 52 // Initialize the host. |
| 52 host_.reset(new ThemeCopyingWidget(browser_view_->GetWidget())); | 53 host_.reset(new ThemeCopyingWidget(browser_view_->GetWidget())); |
| 53 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 54 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 54 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 55 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 55 params.parent = browser_view_->GetWidget()->GetNativeView(); | 56 params.parent = browser_view_->GetWidget()->GetNativeView(); |
| 56 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 57 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 57 host_->Init(params); | 58 host_->Init(params); |
| 58 host_->SetContentsView(clip_view_); | 59 host_->SetContentsView(clip_view.release()); |
| 59 clip_view_->AddChildView(view_); | |
| 60 | 60 |
| 61 SetHostViewNative(host_view); | 61 SetHostViewNative(host_view); |
| 62 | 62 |
| 63 // Start listening to focus changes, so we can register and unregister our | 63 // Start listening to focus changes, so we can register and unregister our |
| 64 // own handler for Escape. | 64 // own handler for Escape. |
| 65 focus_manager_ = host_->GetFocusManager(); | 65 focus_manager_ = host_->GetFocusManager(); |
| 66 if (focus_manager_) { | 66 if (focus_manager_) { |
| 67 focus_manager_->AddFocusChangeListener(this); | 67 focus_manager_->AddFocusChangeListener(this); |
| 68 } else { | 68 } else { |
| 69 // In some cases (see bug http://crbug.com/17056) it seems we may not have | 69 // In some cases (see bug http://crbug.com/17056) it seems we may not have |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 escape, ui::AcceleratorManager::kNormalPriority, this); | 229 escape, ui::AcceleratorManager::kNormalPriority, this); |
| 230 esc_accel_target_registered_ = true; | 230 esc_accel_target_registered_ = true; |
| 231 } | 231 } |
| 232 | 232 |
| 233 void DropdownBarHost::UnregisterAccelerators() { | 233 void DropdownBarHost::UnregisterAccelerators() { |
| 234 DCHECK(esc_accel_target_registered_); | 234 DCHECK(esc_accel_target_registered_); |
| 235 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); | 235 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); |
| 236 focus_manager_->UnregisterAccelerator(escape, this); | 236 focus_manager_->UnregisterAccelerator(escape, this); |
| 237 esc_accel_target_registered_ = false; | 237 esc_accel_target_registered_ = false; |
| 238 } | 238 } |
| OLD | NEW |