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

Side by Side Diff: chrome/browser/ui/views/frame/opaque_browser_frame_view.cc

Issue 8895003: Aura: Add --aura-laptop-mode to fill the workspace with a single window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: maximize ALL the windows Created 9 years 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/frame/opaque_browser_frame_view.h" 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 23 matching lines...) Expand all
34 #include "ui/base/theme_provider.h" 34 #include "ui/base/theme_provider.h"
35 #include "ui/gfx/canvas_skia.h" 35 #include "ui/gfx/canvas_skia.h"
36 #include "ui/gfx/font.h" 36 #include "ui/gfx/font.h"
37 #include "ui/gfx/image/image.h" 37 #include "ui/gfx/image/image.h"
38 #include "ui/gfx/path.h" 38 #include "ui/gfx/path.h"
39 #include "ui/views/controls/button/image_button.h" 39 #include "ui/views/controls/button/image_button.h"
40 #include "ui/views/controls/image_view.h" 40 #include "ui/views/controls/image_view.h"
41 #include "ui/views/widget/root_view.h" 41 #include "ui/views/widget/root_view.h"
42 #include "ui/views/window/window_shape.h" 42 #include "ui/views/window/window_shape.h"
43 43
44 #if defined(USE_AURA)
45 #include "ui/aura/aura_switches.h"
46 #endif
47
44 #if defined(USE_VIRTUAL_KEYBOARD) 48 #if defined(USE_VIRTUAL_KEYBOARD)
45 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h" 49 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h"
46 #endif 50 #endif
47 51
48 namespace { 52 namespace {
49 // The frame border is only visible in restored mode and is hardcoded to 4 px on 53 // The frame border is only visible in restored mode and is hardcoded to 4 px on
50 // each side regardless of the system window border size. 54 // each side regardless of the system window border size.
51 const int kFrameBorderThickness = 4; 55 const int kFrameBorderThickness = 4;
52 // Besides the frame border, there's another 11 px of empty space atop the 56 // Besides the frame border, there's another 11 px of empty space atop the
53 // window in restored mode, to use to drag the window around. 57 // window in restored mode, to use to drag the window around.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 maximize_button_(new views::ImageButton(this))), 127 maximize_button_(new views::ImageButton(this))),
124 ALLOW_THIS_IN_INITIALIZER_LIST( 128 ALLOW_THIS_IN_INITIALIZER_LIST(
125 restore_button_(new views::ImageButton(this))), 129 restore_button_(new views::ImageButton(this))),
126 ALLOW_THIS_IN_INITIALIZER_LIST( 130 ALLOW_THIS_IN_INITIALIZER_LIST(
127 close_button_(new views::ImageButton(this))), 131 close_button_(new views::ImageButton(this))),
128 window_icon_(NULL) { 132 window_icon_(NULL) {
129 ui::ThemeProvider* tp = frame->GetThemeProvider(); 133 ui::ThemeProvider* tp = frame->GetThemeProvider();
130 SkColor color = tp->GetColor(ThemeService::COLOR_BUTTON_BACKGROUND); 134 SkColor color = tp->GetColor(ThemeService::COLOR_BUTTON_BACKGROUND);
131 SkBitmap* background = 135 SkBitmap* background =
132 tp->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND); 136 tp->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND);
137 // TODO(jamescook): Refactor button setup into one button setup function.
133 minimize_button_->SetImage(views::CustomButton::BS_NORMAL, 138 minimize_button_->SetImage(views::CustomButton::BS_NORMAL,
134 tp->GetBitmapNamed(IDR_MINIMIZE)); 139 tp->GetBitmapNamed(IDR_MINIMIZE));
135 minimize_button_->SetImage(views::CustomButton::BS_HOT, 140 minimize_button_->SetImage(views::CustomButton::BS_HOT,
136 tp->GetBitmapNamed(IDR_MINIMIZE_H)); 141 tp->GetBitmapNamed(IDR_MINIMIZE_H));
137 minimize_button_->SetImage(views::CustomButton::BS_PUSHED, 142 minimize_button_->SetImage(views::CustomButton::BS_PUSHED,
138 tp->GetBitmapNamed(IDR_MINIMIZE_P)); 143 tp->GetBitmapNamed(IDR_MINIMIZE_P));
139 if (browser_view->IsBrowserTypeNormal()) { 144 if (browser_view->IsBrowserTypeNormal()) {
140 minimize_button_->SetBackground(color, background, 145 minimize_button_->SetBackground(color, background,
141 tp->GetBitmapNamed(IDR_MINIMIZE_BUTTON_MASK)); 146 tp->GetBitmapNamed(IDR_MINIMIZE_BUTTON_MASK));
142 } 147 }
143 minimize_button_->SetAccessibleName( 148 minimize_button_->SetAccessibleName(
144 l10n_util::GetStringUTF16(IDS_ACCNAME_MINIMIZE)); 149 l10n_util::GetStringUTF16(IDS_ACCNAME_MINIMIZE));
145 AddChildView(minimize_button_); 150 AddChildView(minimize_button_);
146 #if defined(USE_AURA)
147 // TODO(jamescook): Remove this when Aura uses its own custom window frame,
148 // BrowserNonClientFrameViewAura. Layout code depends on this button's
149 // position, so just hide it.
150 minimize_button_->SetVisible(false);
151 #endif
152 151
153 maximize_button_->SetImage(views::CustomButton::BS_NORMAL, 152 maximize_button_->SetImage(views::CustomButton::BS_NORMAL,
154 tp->GetBitmapNamed(IDR_MAXIMIZE)); 153 tp->GetBitmapNamed(IDR_MAXIMIZE));
155 maximize_button_->SetImage(views::CustomButton::BS_HOT, 154 maximize_button_->SetImage(views::CustomButton::BS_HOT,
156 tp->GetBitmapNamed(IDR_MAXIMIZE_H)); 155 tp->GetBitmapNamed(IDR_MAXIMIZE_H));
157 maximize_button_->SetImage(views::CustomButton::BS_PUSHED, 156 maximize_button_->SetImage(views::CustomButton::BS_PUSHED,
158 tp->GetBitmapNamed(IDR_MAXIMIZE_P)); 157 tp->GetBitmapNamed(IDR_MAXIMIZE_P));
159 if (browser_view->IsBrowserTypeNormal()) { 158 if (browser_view->IsBrowserTypeNormal()) {
160 maximize_button_->SetBackground(color, background, 159 maximize_button_->SetBackground(color, background,
161 tp->GetBitmapNamed(IDR_MAXIMIZE_BUTTON_MASK)); 160 tp->GetBitmapNamed(IDR_MAXIMIZE_BUTTON_MASK));
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 // side of the caption buttons. In maximized mode we extend the rightmost 1013 // side of the caption buttons. In maximized mode we extend the rightmost
1015 // button to the screen corner to obey Fitts' Law. 1014 // button to the screen corner to obey Fitts' Law.
1016 int right_extra_width = is_maximized ? 1015 int right_extra_width = is_maximized ?
1017 (kFrameBorderThickness - kFrameShadowThickness) : 0; 1016 (kFrameBorderThickness - kFrameShadowThickness) : 0;
1018 gfx::Size close_button_size = close_button_->GetPreferredSize(); 1017 gfx::Size close_button_size = close_button_->GetPreferredSize();
1019 close_button_->SetBounds(width() - FrameBorderThickness(false) - 1018 close_button_->SetBounds(width() - FrameBorderThickness(false) -
1020 right_extra_width - close_button_size.width(), caption_y, 1019 right_extra_width - close_button_size.width(), caption_y,
1021 close_button_size.width() + right_extra_width, 1020 close_button_size.width() + right_extra_width,
1022 close_button_size.height()); 1021 close_button_size.height());
1023 1022
1024 #if defined(OS_CHROMEOS) && !defined(USE_AURA) 1023 // Both ChromeOS and Aura laptop mode use a single main window.
1025 // LayoutWindowControls could be triggered from 1024 bool single_window_mode = false;
1026 // NativeWidgetGtk::UpdateWindowTitle(), which could happen when user 1025 #if defined(USE_AURA)
sky 2011/12/12 15:46:29 How about a IsSingleWindow() on BrowserFrame?
James Cook 2011/12/12 18:33:36 Oh, good idea! Done.
1027 // navigates in fullscreen mode. And because 1026 single_window_mode =
1028 // BrowserFrameChromeos::IsMaximized() return false for fullscreen mode, we 1027 CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraLaptopMode);
1029 // explicitly test fullscreen mode here and make it use the same code path 1028 #elif defined(OS_CHROMEOS)
1030 // as maximized mode. 1029 single_window_mode = true;
1031 // TODO(oshima): Optimize the relayout logic to defer the frame view's 1030 #endif
1032 // relayout until it is necessary, i.e when it becomes visible. 1031 if (single_window_mode) {
1033 if (is_maximized || frame()->IsFullscreen()) { 1032 // LayoutWindowControls could be triggered from
1034 minimize_button_->SetVisible(false); 1033 // NativeWidgetGtk::UpdateWindowTitle(), which could happen when user
1035 restore_button_->SetVisible(false); 1034 // navigates in fullscreen mode. And because
1036 maximize_button_->SetVisible(false); 1035 // BrowserFrameChromeos::IsMaximized() return false for fullscreen mode, we
1036 // explicitly test fullscreen mode here and make it use the same code path
1037 // as maximized mode.
1038 // TODO(oshima): Optimize the relayout logic to defer the frame view's
1039 // relayout until it is necessary, i.e when it becomes visible.
1040 if (is_maximized || frame()->IsFullscreen()) {
1041 minimize_button_->SetVisible(false);
1042 restore_button_->SetVisible(false);
1043 maximize_button_->SetVisible(false);
1037 1044
1038 if (browser_view()->browser()->is_devtools()) { 1045 if (browser_view()->browser()->is_devtools()) {
1039 close_button_->SetVisible(true); 1046 close_button_->SetVisible(true);
1040 minimize_button_->SetBounds(close_button_->bounds().x(), 0, 0, 0); 1047 minimize_button_->SetBounds(close_button_->bounds().x(), 0, 0, 0);
1041 } else { 1048 } else {
1042 close_button_->SetVisible(false); 1049 close_button_->SetVisible(false);
1043 // Set the bounds of the minimize button so that we don't have to change 1050 // Set the bounds of the minimize button so that we don't have to change
1044 // other places that rely on the bounds. Put it slightly to the right 1051 // other places that rely on the bounds. Put it slightly to the right
1045 // of the edge of the view, so that when we remove the spacing it lines 1052 // of the edge of the view, so that when we remove the spacing it lines
1046 // up with the edge. 1053 // up with the edge.
1047 minimize_button_->SetBounds(width() - FrameBorderThickness(false) + 1054 minimize_button_->SetBounds(width() - FrameBorderThickness(false) +
1048 kNewTabCaptionMaximizedSpacing, 0, 0, 0); 1055 kNewTabCaptionMaximizedSpacing, 0, 0, 0);
1056 }
1057 return;
1049 } 1058 }
1050
1051 return;
1052 } else {
1053 close_button_->SetVisible(true); 1059 close_button_->SetVisible(true);
1054 } 1060 }
1055 #endif
1056 1061
1057 // When the window is restored, we show a maximized button; otherwise, we show 1062 // When the window is restored, we show a maximized button; otherwise, we show
1058 // a restore button. 1063 // a restore button.
1059 bool is_restored = !is_maximized && !frame()->IsMinimized(); 1064 bool is_restored = !is_maximized && !frame()->IsMinimized();
1060 views::ImageButton* invisible_button = is_restored ? 1065 views::ImageButton* invisible_button = is_restored ?
1061 restore_button_ : maximize_button_; 1066 restore_button_ : maximize_button_;
1062 invisible_button->SetVisible(false); 1067 invisible_button->SetVisible(false);
1063 1068
1064 views::ImageButton* visible_button = is_restored ? 1069 views::ImageButton* visible_button = is_restored ?
1065 maximize_button_ : restore_button_; 1070 maximize_button_ : restore_button_;
1066 visible_button->SetVisible(true); 1071 visible_button->SetVisible(true);
1067 visible_button->SetImageAlignment(views::ImageButton::ALIGN_LEFT, 1072 visible_button->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
1068 views::ImageButton::ALIGN_BOTTOM); 1073 views::ImageButton::ALIGN_BOTTOM);
1069 gfx::Size visible_button_size = visible_button->GetPreferredSize(); 1074 gfx::Size visible_button_size = visible_button->GetPreferredSize();
1070 visible_button->SetBounds(close_button_->x() - visible_button_size.width(), 1075 visible_button->SetBounds(close_button_->x() - visible_button_size.width(),
1071 caption_y, visible_button_size.width(), 1076 caption_y, visible_button_size.width(),
1072 visible_button_size.height()); 1077 visible_button_size.height());
1073 1078
1074 #if !defined(USE_AURA) 1079 #if defined(USE_AURA)
1075 // TODO(jamescook): Go back to showing minimize button when Aura uses its 1080 // TODO(jamescook): Go back to showing minimize button when Aura uses its
1076 // own custom window frame, BrowserNonClientFrameViewAura. 1081 // own custom window frame, BrowserNonClientFrameViewAura.
1082 minimize_button_->SetVisible(false);
1083 #else
1077 minimize_button_->SetVisible(true); 1084 minimize_button_->SetVisible(true);
1078 #endif 1085 #endif
1079 minimize_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, 1086 minimize_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
1080 views::ImageButton::ALIGN_BOTTOM); 1087 views::ImageButton::ALIGN_BOTTOM);
1081 gfx::Size minimize_button_size = minimize_button_->GetPreferredSize(); 1088 gfx::Size minimize_button_size = minimize_button_->GetPreferredSize();
1082 minimize_button_->SetBounds( 1089 minimize_button_->SetBounds(
1083 visible_button->x() - minimize_button_size.width(), caption_y, 1090 visible_button->x() - minimize_button_size.width(), caption_y,
1084 minimize_button_size.width(), 1091 minimize_button_size.width(),
1085 minimize_button_size.height()); 1092 minimize_button_size.height());
1086 } 1093 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 1139
1133 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, 1140 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width,
1134 int height) const { 1141 int height) const {
1135 int top_height = NonClientTopBorderHeight(false); 1142 int top_height = NonClientTopBorderHeight(false);
1136 int border_thickness = NonClientBorderThickness(); 1143 int border_thickness = NonClientBorderThickness();
1137 return gfx::Rect(border_thickness, top_height, 1144 return gfx::Rect(border_thickness, top_height,
1138 std::max(0, width - (2 * border_thickness)), 1145 std::max(0, width - (2 * border_thickness)),
1139 std::max(0, height - GetReservedHeight() - 1146 std::max(0, height - GetReservedHeight() -
1140 top_height - border_thickness)); 1147 top_height - border_thickness));
1141 } 1148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698