OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/frame/browser_non_client_frame_view_mus.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_mus.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "chrome/browser/profiles/profiles_state.h" | 9 #include "chrome/browser/profiles/profiles_state.h" |
10 #include "chrome/browser/themes/theme_properties.h" | 10 #include "chrome/browser/themes/theme_properties.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/layout_constants.h" | 12 #include "chrome/browser/ui/layout_constants.h" |
13 #include "chrome/browser/ui/views/frame/browser_frame.h" | 13 #include "chrome/browser/ui/views/frame/browser_frame.h" |
14 #include "chrome/browser/ui/views/frame/browser_frame_mus.h" | 14 #include "chrome/browser/ui/views/frame/browser_frame_mus.h" |
15 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" | 15 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" |
16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
17 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 17 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
18 #include "chrome/browser/ui/views/frame/top_container_view.h" | 18 #include "chrome/browser/ui/views/frame/top_container_view.h" |
19 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" | 19 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" |
20 #include "chrome/browser/ui/views/tab_icon_view.h" | 20 #include "chrome/browser/ui/views/tab_icon_view.h" |
21 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 21 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
22 #include "chrome/browser/web_applications/web_app.h" | 22 #include "chrome/browser/web_applications/web_app.h" |
23 #include "chrome/grit/theme_resources.h" | 23 #include "chrome/grit/theme_resources.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "ui/accessibility/ax_node_data.h" | 25 #include "ui/accessibility/ax_node_data.h" |
26 #include "ui/aura/client/aura_constants.h" | 26 #include "ui/aura/client/aura_constants.h" |
27 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
28 #include "ui/base/hit_test.h" | 28 #include "ui/base/hit_test.h" |
29 #include "ui/base/layout.h" | 29 #include "ui/base/layout.h" |
| 30 #include "ui/base/material_design/material_design_controller.h" |
30 #include "ui/base/theme_provider.h" | 31 #include "ui/base/theme_provider.h" |
31 #include "ui/compositor/layer_animator.h" | 32 #include "ui/compositor/layer_animator.h" |
32 #include "ui/gfx/canvas.h" | 33 #include "ui/gfx/canvas.h" |
33 #include "ui/gfx/geometry/rect_conversions.h" | 34 #include "ui/gfx/geometry/rect_conversions.h" |
34 #include "ui/gfx/image/image_skia.h" | 35 #include "ui/gfx/image/image_skia.h" |
35 #include "ui/gfx/scoped_canvas.h" | 36 #include "ui/gfx/scoped_canvas.h" |
36 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
37 #include "ui/views/layout/layout_constants.h" | 38 #include "ui/views/layout/layout_constants.h" |
38 #include "ui/views/mus/desktop_window_tree_host_mus.h" | 39 #include "ui/views/mus/desktop_window_tree_host_mus.h" |
39 #include "ui/views/mus/window_manager_frame_values.h" | 40 #include "ui/views/mus/window_manager_frame_values.h" |
40 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
41 #include "ui/views/widget/widget_delegate.h" | 42 #include "ui/views/widget/widget_delegate.h" |
42 | 43 |
| 44 #if defined(OS_CHROMEOS) |
| 45 #include "ash/common/ash_layout_constants.h" |
| 46 #endif |
| 47 |
43 #if !defined(OS_CHROMEOS) | 48 #if !defined(OS_CHROMEOS) |
44 #define FRAME_AVATAR_BUTTON | 49 #define FRAME_AVATAR_BUTTON |
45 #endif | 50 #endif |
46 | 51 |
47 namespace { | 52 namespace { |
48 | 53 |
49 #if defined(FRAME_AVATAR_BUTTON) | 54 #if defined(FRAME_AVATAR_BUTTON) |
50 // Space between the new avatar button and the minimize button. | 55 // Space between the new avatar button and the minimize button. |
51 const int kAvatarButtonOffset = 5; | 56 const int kAvatarButtonOffset = 5; |
52 #endif | 57 #endif |
53 // Space between right edge of tabstrip and maximize button. | 58 // Space between right edge of tabstrip and maximize button. |
54 const int kTabstripRightSpacing = 10; | 59 const int kTabstripRightSpacing = 10; |
55 // Height of the shadow of the content area, at the top of the toolbar. | |
56 const int kContentShadowHeight = 1; | |
57 // Space between top of window and top of tabstrip for tall headers, such as | |
58 // for restored windows, apps, etc. | |
59 const int kTabstripTopSpacingTall = 4; | |
60 // Space between top of window and top of tabstrip for short headers, such as | |
61 // for maximized windows, pop-ups, etc. | |
62 const int kTabstripTopSpacingShort = 0; | |
63 // Height of the shadow in the tab image, used to ensure clicks in the shadow | 60 // Height of the shadow in the tab image, used to ensure clicks in the shadow |
64 // area still drag restored windows. This keeps the clickable area large enough | 61 // area still drag restored windows. This keeps the clickable area large enough |
65 // to hit easily. | 62 // to hit easily. |
66 const int kTabShadowHeight = 4; | 63 const int kTabShadowHeight = 4; |
67 | 64 |
68 #if defined(FRAME_AVATAR_BUTTON) | 65 #if defined(FRAME_AVATAR_BUTTON) |
69 // Combines View::ConvertPointToTarget() and View::HitTest() for a given | 66 // Combines View::ConvertPointToTarget() and View::HitTest() for a given |
70 // |point|. Converts |point| from |src| to |dst| and hit tests it against |dst|. | 67 // |point|. Converts |point| from |src| to |dst| and hit tests it against |dst|. |
71 bool ConvertedHitTest(views::View* src, | 68 bool ConvertedHitTest(views::View* src, |
72 views::View* dst, | 69 views::View* dst, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 tab_strip_->AddObserver(this); | 127 tab_strip_->AddObserver(this); |
131 } | 128 } |
132 | 129 |
133 gfx::Rect BrowserNonClientFrameViewMus::GetBoundsForTabStrip( | 130 gfx::Rect BrowserNonClientFrameViewMus::GetBoundsForTabStrip( |
134 views::View* tabstrip) const { | 131 views::View* tabstrip) const { |
135 if (!tabstrip) | 132 if (!tabstrip) |
136 return gfx::Rect(); | 133 return gfx::Rect(); |
137 | 134 |
138 int left_inset = GetTabStripLeftInset(); | 135 int left_inset = GetTabStripLeftInset(); |
139 int right_inset = GetTabStripRightInset(); | 136 int right_inset = GetTabStripRightInset(); |
140 return gfx::Rect(left_inset, GetTopInset(false), | 137 const gfx::Rect bounds(left_inset, GetTopInset(false), |
141 std::max(0, width() - left_inset - right_inset), | 138 std::max(0, width() - left_inset - right_inset), |
142 tabstrip->GetPreferredSize().height()); | 139 tabstrip->GetPreferredSize().height()); |
| 140 return bounds; |
143 } | 141 } |
144 | 142 |
145 int BrowserNonClientFrameViewMus::GetTopInset(bool restored) const { | 143 int BrowserNonClientFrameViewMus::GetTopInset(bool restored) const { |
146 if (!ShouldPaint()) { | 144 if (!ShouldPaint()) { |
147 // When immersive fullscreen unrevealed, tabstrip is offscreen with normal | 145 // When immersive fullscreen unrevealed, tabstrip is offscreen with normal |
148 // tapstrip bounds, the top inset should reach this topmost edge. | 146 // tapstrip bounds, the top inset should reach this topmost edge. |
149 const ImmersiveModeController* const immersive_controller = | 147 const ImmersiveModeController* const immersive_controller = |
150 browser_view()->immersive_mode_controller(); | 148 browser_view()->immersive_mode_controller(); |
151 if (immersive_controller->IsEnabled() && | 149 if (immersive_controller->IsEnabled() && |
152 !immersive_controller->IsRevealed()) { | 150 !immersive_controller->IsRevealed()) { |
153 return (-1) * browser_view()->GetTabStripHeight(); | 151 return (-1) * browser_view()->GetTabStripHeight(); |
154 } | 152 } |
155 return 0; | 153 return 0; |
156 } | 154 } |
157 | 155 |
158 if (browser_view()->IsTabStripVisible()) { | 156 const int header_height = GetHeaderHeight(); |
159 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) | |
160 ? kTabstripTopSpacingShort | |
161 : kTabstripTopSpacingTall; | |
162 } | |
163 | 157 |
164 int caption_buttons_bottom = frame_values().normal_insets.top(); | 158 if (browser_view()->IsTabStripVisible()) |
| 159 return header_height - browser_view()->GetTabStripHeight(); |
165 | 160 |
166 // The toolbar partially overlaps the caption buttons. | 161 return header_height; |
167 if (browser_view()->IsToolbarVisible()) | |
168 return caption_buttons_bottom - kContentShadowHeight; | |
169 | |
170 return caption_buttons_bottom + kClientEdgeThickness; | |
171 } | 162 } |
172 | 163 |
173 int BrowserNonClientFrameViewMus::GetThemeBackgroundXInset() const { | 164 int BrowserNonClientFrameViewMus::GetThemeBackgroundXInset() const { |
174 return 5; | 165 return 5; |
175 } | 166 } |
176 | 167 |
177 void BrowserNonClientFrameViewMus::UpdateThrobber(bool running) { | 168 void BrowserNonClientFrameViewMus::UpdateThrobber(bool running) { |
178 if (window_icon_) | 169 if (window_icon_) |
179 window_icon_->Update(); | 170 window_icon_->Update(); |
180 } | 171 } |
(...skipping 26 matching lines...) Expand all Loading... |
207 tab_strip_bounds.set_y(tab_strip_bounds.y() + top_container_offset); | 198 tab_strip_bounds.set_y(tab_strip_bounds.y() + top_container_offset); |
208 tab_strip_bounds.Intersect(gfx::Rect(size())); | 199 tab_strip_bounds.Intersect(gfx::Rect(size())); |
209 } | 200 } |
210 additional_client_area.push_back(tab_strip_bounds); | 201 additional_client_area.push_back(tab_strip_bounds); |
211 } | 202 } |
212 } | 203 } |
213 aura::WindowTreeHostMus* window_tree_host_mus = | 204 aura::WindowTreeHostMus* window_tree_host_mus = |
214 static_cast<aura::WindowTreeHostMus*>( | 205 static_cast<aura::WindowTreeHostMus*>( |
215 GetWidget()->GetNativeWindow()->GetHost()); | 206 GetWidget()->GetNativeWindow()->GetHost()); |
216 if (show_frame_decorations) { | 207 if (show_frame_decorations) { |
217 window_tree_host_mus->SetClientArea( | 208 const int header_height = GetHeaderHeight(); |
218 views::WindowManagerFrameValues::instance().normal_insets, | 209 gfx::Insets client_area_insets = |
219 additional_client_area); | 210 views::WindowManagerFrameValues::instance().normal_insets; |
| 211 client_area_insets.Set(header_height, client_area_insets.left(), |
| 212 client_area_insets.bottom(), |
| 213 client_area_insets.right()); |
| 214 window_tree_host_mus->SetClientArea(client_area_insets, |
| 215 additional_client_area); |
220 views::Widget* reveal_widget = immersive_mode_controller->GetRevealWidget(); | 216 views::Widget* reveal_widget = immersive_mode_controller->GetRevealWidget(); |
221 if (reveal_widget) { | 217 if (reveal_widget) { |
222 // In immersive mode the reveal widget needs the same client area as | 218 // In immersive mode the reveal widget needs the same client area as |
223 // the Browser widget. This way mus targets the window manager (ash) for | 219 // the Browser widget. This way mus targets the window manager (ash) for |
224 // clicks in the frame decoration. | 220 // clicks in the frame decoration. |
225 static_cast<aura::WindowTreeHostMus*>( | 221 static_cast<aura::WindowTreeHostMus*>( |
226 reveal_widget->GetNativeWindow()->GetHost()) | 222 reveal_widget->GetNativeWindow()->GetHost()) |
227 ->SetClientArea( | 223 ->SetClientArea(client_area_insets, additional_client_area); |
228 views::WindowManagerFrameValues::instance().normal_insets, | |
229 additional_client_area); | |
230 } | 224 } |
231 } else { | 225 } else { |
232 window_tree_host_mus->SetClientArea(gfx::Insets(), additional_client_area); | 226 window_tree_host_mus->SetClientArea(gfx::Insets(), additional_client_area); |
233 } | 227 } |
234 } | 228 } |
235 | 229 |
236 /////////////////////////////////////////////////////////////////////////////// | 230 /////////////////////////////////////////////////////////////////////////////// |
237 // views::NonClientFrameView: | 231 // views::NonClientFrameView: |
238 | 232 |
239 gfx::Rect BrowserNonClientFrameViewMus::GetBoundsForClientView() const { | 233 gfx::Rect BrowserNonClientFrameViewMus::GetBoundsForClientView() const { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 } | 494 } |
501 | 495 |
502 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { | 496 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { |
503 DCHECK(!UsePackagedAppHeaderStyle()); | 497 DCHECK(!UsePackagedAppHeaderStyle()); |
504 const int bottom = frame_values().normal_insets.bottom(); | 498 const int bottom = frame_values().normal_insets.bottom(); |
505 canvas->FillRect( | 499 canvas->FillRect( |
506 gfx::Rect(0, bottom, width(), kClientEdgeThickness), | 500 gfx::Rect(0, bottom, width(), kClientEdgeThickness), |
507 GetThemeProvider()->GetColor( | 501 GetThemeProvider()->GetColor( |
508 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); | 502 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); |
509 } | 503 } |
| 504 |
| 505 int BrowserNonClientFrameViewMus::GetHeaderHeight() const { |
| 506 #if defined(OS_CHROMEOS) |
| 507 // TODO: move ash_layout_constants to ash/public/cpp. |
| 508 const bool restored = !frame()->IsMaximized() && !frame()->IsFullscreen(); |
| 509 return GetAshLayoutSize(restored |
| 510 ? AshLayoutSize::BROWSER_RESTORED_CAPTION_BUTTON |
| 511 : AshLayoutSize::BROWSER_MAXIMIZED_CAPTION_BUTTON) |
| 512 .height(); |
| 513 #else |
| 514 return views::WindowManagerFrameValues::instance().normal_insets.top(); |
| 515 #endif |
| 516 } |
OLD | NEW |