Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/ui/views/dropdown_bar_host.cc

Issue 6913026: Compact Navigation prototype (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Clang build fix. After commit/revert. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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_view.h" 11 #include "chrome/browser/ui/views/dropdown_bar_view.h"
11 #include "chrome/browser/ui/views/frame/browser_view.h" 12 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "ui/base/animation/slide_animation.h" 13 #include "ui/base/animation/slide_animation.h"
13 #include "ui/base/keycodes/keyboard_codes.h" 14 #include "ui/base/keycodes/keyboard_codes.h"
14 #include "ui/gfx/path.h" 15 #include "ui/gfx/path.h"
15 #include "ui/gfx/scrollbar_size.h" 16 #include "ui/gfx/scrollbar_size.h"
16 #include "views/focus/external_focus_tracker.h" 17 #include "views/focus/external_focus_tracker.h"
17 #include "views/focus/view_storage.h" 18 #include "views/focus/view_storage.h"
18 #include "views/widget/widget.h" 19 #include "views/widget/widget.h"
19 20
(...skipping 17 matching lines...) Expand all
37 38
38 // static 39 // static
39 bool DropdownBarHost::disable_animations_during_testing_ = false; 40 bool DropdownBarHost::disable_animations_during_testing_ = false;
40 41
41 //////////////////////////////////////////////////////////////////////////////// 42 ////////////////////////////////////////////////////////////////////////////////
42 // DropdownBarHost, public: 43 // DropdownBarHost, public:
43 44
44 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) 45 DropdownBarHost::DropdownBarHost(BrowserView* browser_view)
45 : browser_view_(browser_view), 46 : browser_view_(browser_view),
46 view_(NULL), 47 view_(NULL),
48 delegate_(NULL),
47 animation_offset_(0), 49 animation_offset_(0),
48 focus_manager_(NULL), 50 focus_manager_(NULL),
49 esc_accel_target_registered_(false), 51 esc_accel_target_registered_(false),
50 is_visible_(false) { 52 is_visible_(false) {
51 } 53 }
52 54
53 void DropdownBarHost::Init(DropdownBarView* view) { 55 void DropdownBarHost::Init(views::View* view,
56 DropdownBarHostDelegate* delegate) {
57 DCHECK(view);
58 DCHECK(delegate);
59
54 view_ = view; 60 view_ = view;
61 delegate_ = delegate;
55 62
56 // Initialize the host. 63 // Initialize the host.
57 host_.reset(views::Widget::CreateWidget()); 64 host_.reset(views::Widget::CreateWidget());
58 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); 65 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
59 params.delete_on_destroy = false; 66 params.delete_on_destroy = false;
60 params.parent_widget = browser_view_->GetWidget(); 67 params.parent_widget = browser_view_->GetWidget();
61 host_->Init(params); 68 host_->Init(params);
62 host_->SetContentsView(view_); 69 host_->SetContentsView(view_);
63 70
64 // Start listening to focus changes, so we can register and unregister our 71 // Start listening to focus changes, so we can register and unregister our
(...skipping 30 matching lines...) Expand all
95 if (!is_visible_) { 102 if (!is_visible_) {
96 // Don't re-start the animation. 103 // Don't re-start the animation.
97 is_visible_ = true; 104 is_visible_ = true;
98 animation_->Reset(); 105 animation_->Reset();
99 animation_->Show(); 106 animation_->Show();
100 } 107 }
101 } 108 }
102 } 109 }
103 110
104 void DropdownBarHost::SetFocusAndSelection() { 111 void DropdownBarHost::SetFocusAndSelection() {
105 view_->SetFocusAndSelection(true); 112 delegate_->SetFocusAndSelection(true);
106 } 113 }
107 114
108 bool DropdownBarHost::IsAnimating() const { 115 bool DropdownBarHost::IsAnimating() const {
109 return animation_->is_animating(); 116 return animation_->is_animating();
110 } 117 }
111 118
112 void DropdownBarHost::Hide(bool animate) { 119 void DropdownBarHost::Hide(bool animate) {
113 if (!IsVisible()) 120 if (!IsVisible())
114 return; 121 return;
115 if (animate && !disable_animations_during_testing_) { 122 if (animate && !disable_animations_during_testing_ &&
116 animation_->Reset(1.0); 123 !animation_->IsClosing()) {
117 animation_->Hide(); 124 animation_->Hide();
118 } else { 125 } else {
119 StopAnimation(); 126 if (animation_->IsClosing()) {
120 is_visible_ = false; 127 // If we're in the middle of a close animation, skip immediately to the
121 host_->Hide(); 128 // end of the animation.
129 StopAnimation();
130 } else {
131 // Otherwise we need to set both the animation state to ended and the
132 // DropdownBarHost state to ended/hidden, otherwise the next time we try
133 // to show the bar, it might refuse to do so. Note that we call
134 // AnimationEnded ourselves as Reset does not call it if we are not
135 // animating here.
136 animation_->Reset();
137 AnimationEnded(animation_.get());
138 }
122 } 139 }
123 } 140 }
124 141
125 void DropdownBarHost::StopAnimation() { 142 void DropdownBarHost::StopAnimation() {
126 animation_->End(); 143 animation_->End();
127 } 144 }
128 145
129 bool DropdownBarHost::IsVisible() const { 146 bool DropdownBarHost::IsVisible() const {
130 return is_visible_; 147 return is_visible_;
131 } 148 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * 181 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) *
165 pref_size.height()); 182 pref_size.height());
166 183
167 // This call makes sure it appears in the right location, the size and shape 184 // This call makes sure it appears in the right location, the size and shape
168 // is correct and that it slides in the right direction. 185 // is correct and that it slides in the right direction.
169 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); 186 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect());
170 SetDialogPosition(dlg_rect, false); 187 SetDialogPosition(dlg_rect, false);
171 188
172 // Let the view know if we are animating, and at which offset to draw the 189 // Let the view know if we are animating, and at which offset to draw the
173 // edges. 190 // edges.
174 view_->set_animation_offset(animation_offset_); 191 delegate_->SetAnimationOffset(animation_offset_);
175 view_->SchedulePaint(); 192 view_->SchedulePaint();
176 } 193 }
177 194
178 void DropdownBarHost::AnimationEnded(const ui::Animation* animation) { 195 void DropdownBarHost::AnimationEnded(const ui::Animation* animation) {
179 // Place the dropdown widget in its fully opened state. 196 // Place the dropdown widget in its fully opened state.
180 animation_offset_ = 0; 197 animation_offset_ = 0;
181 198
182 if (!animation_->IsShowing()) { 199 if (!animation_->IsShowing()) {
183 // Animation has finished closing. 200 // Animation has finished closing.
184 host_->Hide(); 201 host_->Hide();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 focus_manager_->RegisterAccelerator(escape, this); 332 focus_manager_->RegisterAccelerator(escape, this);
316 esc_accel_target_registered_ = true; 333 esc_accel_target_registered_ = true;
317 } 334 }
318 335
319 void DropdownBarHost::UnregisterAccelerators() { 336 void DropdownBarHost::UnregisterAccelerators() {
320 DCHECK(esc_accel_target_registered_); 337 DCHECK(esc_accel_target_registered_);
321 views::Accelerator escape(ui::VKEY_ESCAPE, false, false, false); 338 views::Accelerator escape(ui::VKEY_ESCAPE, false, false, false);
322 focus_manager_->UnregisterAccelerator(escape, this); 339 focus_manager_->UnregisterAccelerator(escape, this);
323 esc_accel_target_registered_ = false; 340 esc_accel_target_registered_ = false;
324 } 341 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/dropdown_bar_host.h ('k') | chrome/browser/ui/views/dropdown_bar_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698